日期:2014-05-17  浏览次数:21239 次

C#播放视频时与暴风影音冲突的问题

如果你在使用C#中AxWindowsMediaPlayer控件进行视频播放,但是却与暴风影音软件造成冲突,下面的代码也许能给你带来帮助。
使用AxWindowsMediaPlayer进行播放时在某些情况下与暴风影音有冲突,当安装了暴风影音播放则正常;卸载了暴风影音后播放时只有声音没有图片。那么此时需要注册暴风影音用到的几个文件,分别是:ffmpeg.dll、ffdshow.ax、ffmpeg.dll、libmpeg2_ff.dll这几个文件要放在一起注册至注册表中。下面的代码中注册的值是通过手动测试而得的,测试方法是安装暴风影音和卸载暴风影音后注册表值的差别而得出的必须要注册的值。不一定能使用所有场合,请大家参考使用。
直接看代码:

public class RegFFDShow
    {
        [DllImport("DLL\\ffdshow.ax")]//ffdshow.ax放的路径,当前代码放的是运行目录下DLL文件下
        public static extern int DllRegisterServer();

        public static void RegFFDSHOW()
        {
            if (Regffdshow_ax() != -1)
            {
                Regffdshow();
            }
        }

        private static int Regffdshow_ax()
        {
            RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(@"CLSID\{4DB2B5D9-4556-4340-B189-AD20110D953F}");

            if (registryKey == null)
            {
                int i = DllRegisterServer();

                if (i >= 0)//注册成功!
                {
                    return 0;
                }
                else//注册失败
                {
                    return -1;
                }
            }
            else
            {
                return 1;
            }
        }

        private static bool Regffdshow()
        {
            string strS1521 = string.Empty;

            RegistryKey RegLocalmachine;

            RegistryKey regKeySoftware;

            RegistryKey regKeyffdshowGNU;

            RegistryKey regKeyffdshow;

            RegistryKey ffdshowDefault;

            RegLocalmachine = Registry.LocalMachine;

            regKeySoftware = RegLocalmachine.CreateSubKey("Software");

            regKeyffdshowGNU = regKeySoftware.CreateSubKey("GNU");

            regKeyffdshow = regKeyffdshowGNU.CreateSubKey("ffdshow");
            //所有的要用到的暴风影音组件所在的文件夹
            regKeyffdshow.SetValue("pth", Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, @"\DLL"));

            string[] strSubKeyNames = Registry.Users.GetSubKeyNames();

            foreach (string strSubKeyName in strSubKeyNames)
            {
                if (strSubKeyName.StartsWith("S-1-5-21-") && strSubKeyName.EndsWith("_Classes"))
                {
                    strS1521 = strSubKeyName;

                    break;
                }
            }

            RegistryKey registryKey = Registry.Users.OpenSubKey(strS1521.Replace("_Classes", "") + @"\SOFTWARE\GNU\ffdshow");

            //if (registryKey != null)
            //{
            //    return true;
            //}

            try
            {
                RegistryKey regKeyS1521 = Registry.Users.CreateSubKey(strS1521.Replace("_Classes", ""));

                regKeySoftware = regKeyS1521.CreateSubKey("Software");

                regKeyffdshowGNU = regKeySoftware.CreateSubKey("GNU");

                regKeyffdshow = regKeyffdshowGNU.CreateSubKey("ffdshow");

 

                string[] strffdshow = new string[40] {
                "fastH264",
                "subTextpin",
                "subTextpinSSA",
                "isBlacklist",
                "isWhitelist",
                "cscd",
                "div3",
                "duck",
                "dx50",
                "ffv1",
                "flv1",
                "fvfw",
                "h261",
                "h263",
                "h264",
                "hfyu",
                "iv32",
                "mjpg",
                "mp41",
                "mp42",
                "mp43",
                "mp4v",