0

I would like to disable a webbrowser sound but i don't think it's possible so i saw that it was possible to disable an application sound on systems higher than win xp, now i just need to know how and i can't find it!

Current code :

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

i don't think there is a webrowser.noSound thing , also i used activeform.hide() to hide the webbrowser

user3352374
  • 37
  • 2
  • 10

1 Answers1

1

First add this name space :

using System.Runtime.InteropServices;

Now you can simply disable all audio output. Try these codes :

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

Update :

You can Read This someone else also answered this question.

Update 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.

Read these two similar questions and disable the sound : Question1 Question2

Update 3 :

For IE7 and above you can use 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);

Here is the Source

Update 4 :

How to mute windows sound

Community
  • 1
  • 1
Ali Vojdanian
  • 2,067
  • 2
  • 31
  • 47
  • I tried it and the way my thing is coded it just doesn't fit in, it does nothing, also if i use Form.ActiveForm.Hide(); , i think the webbrowser just won't load as i hear no sound when i do it – user3352374 Jan 29 '15 at 15:07
  • Tried and i think this only stops the navigation sounds of clicks right? Because i tried it and it didn't do anything :S – user3352374 Jan 29 '15 at 19:40
  • @user3352374 It also stops the navigation sounds of clicks. You can mute system sounds, too. If you want. ;) – Ali Vojdanian Jan 29 '15 at 19:42
  • Basically i would need to stop system sounds for my application, can the cointernetsetfeatureenabled does it? if so i don't see how :O – user3352374 Jan 29 '15 at 19:45
  • @user3352374 It's so simple. See the update 4 and I showed a link of a tutorial for that. If you got your answer mark this as correct answer. ;) – Ali Vojdanian Jan 29 '15 at 19:49
  • Alright thanks for everything understood how it works etc.. Now i just get the part where it says that there is no GetVolume method in the .dll – user3352374 Jan 29 '15 at 20:09
  • @user3352374 Read http://www.geekpedia.com/tutorial176_Get-and-set-the-wave-sound-volume.html for muting system sound. – Ali Vojdanian Jan 29 '15 at 20:13
  • found why i find it so hard, basically it mutes the form but not the web browser , i just checked o.O – user3352374 Jan 29 '15 at 20:22
  • @user3352374 It definitely helps you. http://www.dotnetcurry.com/showarticle.aspx?ID=431 – Ali Vojdanian Jan 29 '15 at 20:31
  • I know how to do it, it's just that it mutes the windows form that launch the webBrowser , but the webBrowser is in another form, i don't know how to make the webBrowser inside that Form even though i use http://prntscr.com/5yoeov which is the webbrowser in the form – user3352374 Jan 29 '15 at 20:55
  • @user3352374 Add webbrowser in your form or you can use child form for that. – Ali Vojdanian Jan 29 '15 at 21:05