2013-03-30 16 views
10

我的網頁瀏覽器:的Webbrowser禁用所有音頻輸出 - 從網上電臺到YouTube

XAML:

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

代碼:

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聲音來完成,但我不能真正bielieve,我不能在代碼中做到這一點。

回答

9

以下是您可以輕鬆完成的方法。雖然不是特定於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"); 
     } 
    } 
} 
+2

不幸的是我錯過了OP問題中有關整個應用程序靜音的部分;我提供了一個賞金,希望得到一個特定於網絡瀏覽器控件的解決方案(因爲我的應用程序有其他音頻來源)。你不會碰巧知道更具針對性的方法嗎?無論哪種方式,這*都*很好地回答了OP問題。 – JYelton

+0

我會看看它。不知道是否可以完成。 – Noseratio

+0

我不認爲這是可能的。我試着將[APPCOMMAND_VOLUME_MUTE](http://stackoverflow.com/questions/154089/mute-windows-volume-using-c-sharp)發送到WebBrowser的整個子窗口樹,最好的結果是全球靜音。 – Noseratio

0

你可以嘗試以及使用DISPID_AMBIENT_DLCONTROL

DLCTL_DLIMAGES,DLCTL_VIDEOS和DLCTL_BGSOUNDS:圖片,視頻,以及背景聲音會從服務器下載並顯示,或者如果這些標誌是打組。如果沒有設置標誌,它們將不會被下載和顯示。