c# - Webbrowser 禁用所有音频输出 - 从在线广播到 youtube

标签 c# wpf browser

我的浏览器:

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% 静音,完全没有声音。

我读到在这个网络浏览器中它需要通过 Windows Sounds 来完成,但我真的不能相信我不能在代码中做到这一点。

最佳答案

这里是您可以轻松完成的方法。虽然不是特定于 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");
        }
    }
}

关于c# - Webbrowser 禁用所有音频输出 - 从在线广播到 youtube,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15720803/

相关文章:

c# - WPF 全局异常处理程序

c# - 将 DataGrid 的一行传递给另一个 wpf 表单 c#

mysql - 当我向 'download' 发出请求时,浏览器下载的 'localhost:3306' 文件的用途是什么?

c# - 从 usercontrol viewmodel 到 customUsercontrol Viewmodel 的 Unity 依赖注入(inject)

c# - 包含对多列的查询

c# - 根据本地时间从数据库中检索记录

c# - 日期时间转换为无效格式

c# - 如何使用 Wpf、MVVM 获取图像像素位置和 RGB 值?

html - 如何告诉浏览器不要提供保存不正确的密码?

javascript - 如何解决 devicemotion 脚本的问题?