wpf 网络浏览器禁用所有音频输出 - 从在线广播到 youtube
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15720803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Webbrowser disable all audio output - from online radio to youtube
提问by Finchsize
My webbrowser:
我的浏览器:
XAML:
XAML:
//...
xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
//...
<my:WindowsFormsHost Name="windowsFormsHost"/>
Code behind C#:
C# 背后的代码:
System.Windows.Forms.WebBrowser Browser = new System.Windows.Forms.WebBrowser();
windowsFormsHost.Child = Browser;
My question is how to disable all audio output.
我的问题是如何禁用所有音频输出。
I found this:
我找到了这个:
C#:
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);
Its fine, but this code disable only "click" sound, so its kind of useless in this case.
很好,但是此代码仅禁用“单击”声音,因此在这种情况下它是无用的。
I just want from my application 100% mute, no sounds at all.
我只想让我的应用程序 100% 静音,完全没有声音。
I've read that in this webbrowser it need to be done through Windows Sounds, but I cant really bielieve that I cant do this in code.
我读过在这个 webbrowser 中它需要通过 Windows Sounds 来完成,但我真的不能相信我不能在代码中做到这一点。
采纳答案by noseratio
Here is how you can do it with ease. Not specific to WebBrowser though, but does what you requested: I just want from my application 100% mute, no sounds at all.
这是您可以轻松完成的方法。虽然不是特定于 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");
}
}
}
回答by volody
You can try as well to use DISPID_AMBIENT_DLCONTROL
您也可以尝试使用DISPID_AMBIENT_DLCONTROL
DLCTL_DLIMAGES, DLCTL_VIDEOS, and DLCTL_BGSOUNDS: Images, videos, and background sounds will be downloaded from the server and displayed or played if these flags are set. They will not be downloaded and displayed if the flags are not set.
DLCTL_DLIMAGES、DLCTL_VIDEOS 和 DLCTL_BGSOUNDS:如果设置了这些标志,将从服务器下载图像、视频和背景声音并显示或播放。如果未设置标志,它们将不会被下载和显示。

