c# - C#禁用Webbrowser声音/应用程序声音

标签 c# audio browser

我想禁用Web浏览器声音,但我认为这是不可能的,因此我看到可以在高于win xp的系统上禁用应用程序声音,现在我只需要知道该怎么做,而我找不到它!

当前代码:

Form.ActiveForm.Hide();
        webBrowser1.ScriptErrorsSuppressed = true;
        try
        {
            webBrowser1.Navigate(args[2], null, null, "User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Xbox; Xbox One)");
        }
        catch (Exception ex)
        {
            Environment.Exit(0);
        }

我不认为有webrowser.noSound的东西,我也用activeform.hide()来隐藏webbrowser

最佳答案

首先添加此 namespace :

using System.Runtime.InteropServices;

现在,您只需禁用所有音频输出即可。试试这些代码:
[DllImport("winmm.dll")]
    public static extern int GetVolume(IntPtr p, out uint volume);

    [DllImport("winmm.dll")]
    public static extern int SetVolume(IntPtr p, uint volume);

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        // Save the current volume
        int save;
        GetVolume(IntPtr.Zero, out save);

        this.FormClosing += delegate 
        {
            // Restore the volume 
            SetVolume(IntPtr.Zero, save);
        };

        // Now you can mute sounds
        SetVolume(IntPtr.Zero, 0);
        string url = "http://www.example.com";
        this.webBrowser1.Navigate(url);
    }

更新:

您可以Read This其他人也回答了这个问题。

更新2:

You can put it inside a static class and either make the CoInternetSetFeatureEnabled method public, or add an additional bridge method that calls it after converting the parameters from a more usable form, if necessary.



阅读这两个类似的问题并禁用声音:
Question1 Question2

更新3:

对于IE7及更高版本,您可以使用CoInternetSetFeatureEnabled:
// Constants
private const int FEATURE_DISABLE_NAVIGATION_SOUNDS = 21;
private const int SET_FEATURE_ON_THREAD = 0x00000001;
private const int SET_FEATURE_ON_PROCESS = 0x00000002;
private const int SET_FEATURE_IN_REGISTRY = 0x00000004;
private const int SET_FEATURE_ON_THREAD_LOCALMACHINE = 0x00000008;
private const int SET_FEATURE_ON_THREAD_INTRANET = 0x00000010;
private const int SET_FEATURE_ON_THREAD_TRUSTED = 0x00000020;
private const int SET_FEATURE_ON_THREAD_INTERNET = 0x00000040;
private const int SET_FEATURE_ON_THREAD_RESTRICTED = 0x00000080;

// Necessary dll import
[DllImport("urlmon.dll")]
[PreserveSig]
[return:MarshalAs(UnmanagedType.Error)]
static extern int CoInternetSetFeatureEnabled(
int FeatureEntry,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
bool fEnable);

......

// You can call the CoInternetSetFeatureEnabled like this:
CoInternetSetFeatureEnabled(FEATURE_DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, true);

这是Source

更新4:

How to mute windows sound

关于c# - C#禁用Webbrowser声音/应用程序声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28217411/

相关文章:

javascript - 创建 youtube 流 HTML5 的音频频谱

java - 程序在 Eclipse 中可以运行,但是当我导出到可运行的 JAR 时,它就不能运行。文件未找到异常

javascript - 如何从 Web 浏览器的控制台隐藏 ajax 请求

javascript - 如何防止用户在 Jquery Mobile 中点击浏览器后退按钮时离开页面?

c# - C# "The type or namespace cannot be found"的新手

c# - 类名的 CompilerServices

C# - 屏蔽文本框(如何去掉其中的下划线)

java - 如何用Java处理声音?

c# - 如何使用 .net webBrowser 对象

c# - Windows 回调,当事件窗口改变时