web浏览器禁用所有音频输出 - 从在线广播到YouTube [英] Webbrowser disable all audio output - from online radio to youtube

查看:121
本文介绍了web浏览器禁用所有音频输出 - 从在线广播到YouTube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页浏览器:

XAML:

//...
xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
//...
<my:WindowsFormsHost Name="windowsFormsHost"/>

背后的C#code:

Code behind C#:

System.Windows.Forms.WebBrowser Browser = new System.Windows.Forms.WebBrowser();
windowsFormsHost.Child = Browser;

我的问题是如何禁用所有的音频输出。

My question is how to disable all audio output.

我发现这一点:

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);

其优良的,但是这code禁止唯一的咔嚓声,所以其在这种情况下,一种无用的。

Its fine, but this code disable only "click" sound, so its kind of useless in this case.

我刚刚从我的应用程序要100%静音,根本没有任何声音。

I just want from my application 100% mute, no sounds at all.

我读过,在这个网页浏览器就需要通过Windows声音来完成,但我真的不能bielieve,我不能在code做到这一点。

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.

推荐答案

下面是你如何能轻松做到这一点。不特定于web浏览器,虽然,但做你的要求是什么:我只是从我的应用程序要100%静音,无声音在所有

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.

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");
        }
    }
}

这篇关于web浏览器禁用所有音频输出 - 从在线广播到YouTube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆