c# – Webbrowser禁用所有音频输出 – 从在线广播到YouTube
发布时间:2020-12-15 03:44:45 所属栏目:百科 来源:网络整理
导读:我的webbrowser: XAML: //...xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"//...my:WindowsFormsHost Name="windowsFormsHost"/ C#后面的代码: System.Windows.Forms.WebBrowser Browser = new System.Wi
我的webbrowser:
XAML: //... xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" //... <my:WindowsFormsHost Name="windowsFormsHost"/> C#后面的代码: System.Windows.Forms.WebBrowser Browser = new System.Windows.Forms.WebBrowser(); windowsFormsHost.Child = Browser; 我的问题是如何禁用所有音频输出. 我找到了这个: C#: private const int Feature = 21; //FEATURE_DISABLE_NAVIGATION_SOUNDS private const int SetFeatureOnProcess = 0x00000002; [DllImport("urlmon.dll")] [PreserveSig] [return: MarshalAs(UnmanagedType.Error)] static extern int CoInternetSetFeatureEnabled(int featureEntry,[MarshalAs(UnmanagedType.U4)] int dwFlags,bool fEnable); 它的罚款,但这个代码只禁用“点击”的声音,所以在这种情况下它是无用的. 我只想从我的应用程序100%静音,没有任何声音. 我已经看到,在这个webbrowser它需要通过Windows Sounds完成,但我不能真正的bielieve,我不能在代码中做到这一点. 解决方法
这是你如何轻松地做到这一点.不是特定于WebBrowser,但是做了你所要求的:我只是想从我的应用程序100%静音,没有任何声音.
using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace WinformsWB { public partial class Form1 : Form { [DllImport("winmm.dll")] public static extern int waveOutGetVolume(IntPtr h,out uint dwVolume); [DllImport("winmm.dll")] public static extern int waveOutSetVolume(IntPtr h,uint dwVolume); public Form1() { InitializeComponent(); } private void Form1_Load(object sender,EventArgs e) { // save the current volume uint _savedVolume; waveOutGetVolume(IntPtr.Zero,out _savedVolume); this.FormClosing += delegate { // restore the volume upon exit waveOutSetVolume(IntPtr.Zero,_savedVolume); }; // mute waveOutSetVolume(IntPtr.Zero,0); this.webBrowser1.Navigate("http://youtube.com"); } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |