Webbrowser disable all audio output - from online radio to youtube

后端 未结 2 1764
野趣味
野趣味 2020-12-17 18:48

My webbrowser:

XAML:

//...
xmlns:my=\"clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration\"
//...


        
相关标签:
2条回答
  • 2020-12-17 19:29

    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");
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-17 19:43

    You can try as well to use 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.

    0 讨论(0)
提交回复
热议问题