Since 1.8.1 DotNetBrowser provides API that allows muting/unmuting audio on the loaded web page and checking whether audio is muted or not. The Browser.AudioMuted property allows to mute the audio and check if the audio is already muted.


To mute audio, set this property to true:

C#

browser.AudioMuted = true;

VB.NET

browser.AudioMuted = True


The value of this property can be used to check whether audio is muted:

C#

var muted = browser.AudioMuted;

VB.NET

Dim muted = browser.AudioMuted


It is also possible to determine whether the browser is currently playing audio. The Browser.AudioMuted property is set to true in this case.


The complete example that demonstrates how to mute audio on the opened web page and check whether audio is muted or not is given below.


Example

C#

using DotNetBrowser;
using DotNetBrowser.WPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
namespace MuteAudioSample
{
    class Program
    {
       public class WindowMain : Window
       {
           private Button muteButton;
           public WPFBrowserView browserView;
           private Grid layout;
           public WindowMain()
           {
               layout = new Grid();
               ColumnDefinition gridCol1 = new ColumnDefinition();
               layout.ColumnDefinitions.Add(gridCol1);
               RowDefinition gridRow1 = new RowDefinition();
               gridRow1.Height = new GridLength(45);
               RowDefinition gridRow2 = new RowDefinition();
               layout.RowDefinitions.Add(gridRow1);
               layout.RowDefinitions.Add(gridRow2);
               Content = layout;
               browserView = new WPFBrowserView(BrowserFactory.Create());
               Grid.SetRow(browserView, 1);
               Grid.SetColumn(browserView, 0);
               muteButton = new Button();
               UpdateButtonText(muteButton, browserView.Browser);
               muteButton.Height = 23;
               muteButton.Click += muteButton_Click;
               Grid.SetRow(muteButton, 0);
               Grid.SetColumn(muteButton, 0);
               layout.Children.Add(muteButton);
               layout.Children.Add(browserView);
               Width = 1024;
               Height = 768;
               this.Loaded += WindowMain_Loaded;
           }
           private void muteButton_Click(object sender, RoutedEventArgs e)
           {
               browserView.Browser.AudioMuted = !browserView.Browser.AudioMuted;
               UpdateButtonText(muteButton, browserView.Browser);
           }
           void WindowMain_Loaded(object sender, RoutedEventArgs e)
           {
               browserView.Browser.LoadURL("https://www.youtube.com/");
           }
           private static void UpdateButtonText(Button button, Browser browser)
           {
               Application.Current.Dispatcher.BeginInvoke((Action) (() => {

               button.Content = browser.AudioMuted ? "Unmute Audio" : "Mute Audio";
           }));
    }
           [STAThread]
           public static void Main()
           {
               Application app = new Application();
               WindowMain wnd = new WindowMain();
               app.Run(wnd);
               var browser = wnd.browserView.Browser;
               wnd.browserView.Dispose();
               browser.Dispose();
           }
       }
    }
}

VB.NET

Imports System.Windows
Imports System.Windows.Controls
Imports DotNetBrowser
Imports DotNetBrowser.WPF

Public Class WindowMain
    Inherits Window

    Private muteButton As Button
    Public browserView As WPFBrowserView
    Private layout As Grid

    Sub New()
        layout = new Grid()
        Dim gridCol1 As ColumnDefinition = new ColumnDefinition()
        layout.ColumnDefinitions.Add(gridCol1)
        Dim gridRow1 As RowDefinition = new RowDefinition()
        gridRow1.Height = new GridLength(45)
        Dim gridRow2 As RowDefinition = new RowDefinition()
        layout.RowDefinitions.Add(gridRow1)
        layout.RowDefinitions.Add(gridRow2)
        Content = layout
        browserView = new WPFBrowserView(BrowserFactory.Create())
        Grid.SetRow(browserView, 1)
        Grid.SetColumn(browserView, 0)
        muteButton = new Button()
        UpdateButtonText(muteButton, browserView.Browser)
        muteButton.Height = 23
        AddHandler muteButton.Click, AddressOf muteButton_Click
        Grid.SetRow(muteButton, 0)
        Grid.SetColumn(muteButton, 0)
        layout.Children.Add(muteButton)
        layout.Children.Add(browserView)
        Width = 1024
        Height = 768
        AddHandler Loaded, AddressOf WindowMain_Loaded
    End Sub

    Private Sub muteButton_Click(sender As Object, e As RoutedEventArgs)
        browserView.Browser.AudioMuted = Not browserView.Browser.AudioMuted
        UpdateButtonText(muteButton, browserView.Browser)
    End Sub

    Private Sub WindowMain_Loaded(sender As Object, e As RoutedEventArgs)
        browserView.Browser.LoadURL("https://www.youtube.com/")
    End Sub

    Private Shared Sub UpdateButtonText(button As Button, browser As Browser)
        Application.Current.Dispatcher.BeginInvoke(
            Sub()
               button.Content = IF(browser.AudioMuted, "Unmute Audio", "Mute Audio")
           End Sub)
    End Sub
End Class

Module Module1
    <STAThread>
    Sub Main()
        Dim app As Application = New Application()
        Dim wnd As WindowMain = New WindowMain()
        app.Run(wnd)
        Dim browser = wnd.browserView.Browser
        wnd.browserView.Dispose()
        browser.Dispose()
    End Sub
End Module