如果你在使用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", "mszh", "png1", "qtrle", "qtrpza", "raw_rawv", "rt21", "svq1", "svq3", "theo", "vp3", "vp5", "vp6", "vp6f", "xvid", "zlib", "supDVDdec", "mpg2", "trayIcon" }; int[] nffdshow = new int[40] { 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x015, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 }; for (int i = 0; i < strffdshow.Length; i++) { regKeyffdshow.SetValue(strffdshow[i], nffdshow[i]); } ffdshowDefault = regKeyffdshow.CreateSubKey("default"); string[] strffdshow_default = new string[6]{ "postprocH264mode", "resizeMethod", "subIsExpand", "isSubtitles", "isOSD", "threadsnum" }; int[] nffdshow_default = new int[6]{ 0x00, 0x09, 0x00, 0x00, 0x00, 0x02 }; for (int i = 0; i < strffdshow_default.Length; i++) { ffdshowDefault.SetValue(strffdshow_default[i], nffdshow_default[i]); } ffdshowDefault.Close(); RegistryKey regKeyffdshow_audio = regKeyffdshowGNU.CreateSubKey("ffdshow_audio"); RegistryKey regKeyffdshow_audio_default = regKeyffdshow_audio.CreateSubKey("default"); string[] strffdshow_audio = new string[18]{ "isBlacklist", "isWhitelist", "aac", "ac3", "amr", "dts", "eac3", "flac", "lpcm", "mace", "truehd", "mlp", "mp2", "mp3", "qdm2", "tta", "vorbis", "trayIcon"}; int[] nffdshow_audio = new int[18]{ 0x01, 0x00, 0x08, 0x0f, 0x01, 0x01, 0x01, 0x01, 0x04, 0x01, 0x01, 0x01, 0x07, 0x07, 0x01, 0x01, 0x01, 0x00}; for (int i = 0; i < strffdshow_audio.Length; i++) { regKeyffdshow_audio.SetValue(strffdshow_audio[i], nffdshow_audio[i]); } string[] strffdshow_audio_default = new string[8]{ "mixerNormalizeMatrix", "volNormalize", "ismixer", "mixerOut", "passthroughAC3", "passthroughDTS", "decoderDRC", "isOSD" }; int[] nffdshow_audio_default = new int[8]{ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 }; for (int i = 0; i < strffdshow_audio_default.Length; i++) { regKeyffdshow_audio.SetValue(strffdshow_audio_default[i], nffdshow_audio_default[i]); } regKeyffdshow_audio_default.Close(); RegistryKey regKeyffdshow_DXVA = regKeyffdshowGNU.CreateSubKey("ffdshow_DXVA"); string[] strffdshow_DXVA = new string[3]{ "isCompMgr", "isBlacklist", "isWhitelist"}; int[] nffdshow_DXVA = new int[3]{ 0x00, 0x00, 0x01}; for (int i = 0; i < strffdshow_DXVA.Length; i++) { regKeyffdshow_DXVA.SetValue(strffdshow_DXVA[i], nffdshow_DXVA[i]); } regKeyffdshow_DXVA.SetValue("Whitelist", "bsplayer.exe;coreplayer.exe;ehshell.exe;" + "gom.exe;graphedit.exe;graphedt.exe;graphstudio.exe;" + "graphstudio64.exe;kmplayer.exe;mpc-hc.exe;mpc-hc64.exe;" + "mplayerc.exe;wmplayer.exe;zplayer.exe;"); regKeyffdshow_DXVA.Close(); regKeyffdshowGNU.Close(); regKeySoftware.Close(); regKeyS1521.Close(); Registry.Users.Close(); RegLocalmachine.Close(); return true; } catch { return false; } } }
调用:
RegFFDShow.RegFFDSHOW();
就可以完成注册所有组件,播放也就没有问题了。
ffdshow组件及本章代码下载:http://download.csdn.net/detail/yysyangyangyangshan/4914610