0

I modified the volume for my game with naudio and it is now completely muted, how do I make the sound work again?

This is the code:

 private readonly WaveOutEvent Music_Output = new WaveOutEvent();

//I play the music on a timed event, you can ignore this detail;

private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
        {

            UnmanagedMemoryStream sound1 = Properties.Resources.Cycle_Sort_1;
            //the sound I am playing

            byte[] b = ReadToEnd(sound1);
            //ReadToEnd is an external bytestreaming function that is unrelated to my 
            //issue so you can ignore it.
            WaveStream wav = new RawSourceWaveStream(new MemoryStream(b), new WaveFormat(44100, 16, 2));
            Music_Output.Init(wav);
            Music_Output.Volume = 0;
            //THIS IS THE LINE THE BUGGED MY ENTIRE AUDIO FOR THE GAME;
            //After I ran this line, the whole audio for the game is mute forever, no 
            //matter what I do
            Music_Output.Play();
        }

After that I returned the volume back to normal

 private readonly WaveOutEvent Music_Output = new WaveOutEvent();

//I play the music on a timed event, you can ignore this detail;

private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
        {

            UnmanagedMemoryStream sound1 = Properties.Resources.Cycle_Sort_1;

            byte[] b = ReadToEnd(sound1);

            WaveStream wav = new RawSourceWaveStream(new MemoryStream(b), new WaveFormat(44100, 16, 2));
            Music_Output.Init(wav);
            Music_Output.Volume = 100;
            Music_Output.Play();
        }

but everything is STILL MUTED for NO REASON! Can anyone help me with this weird issue?

omoor
  • 73
  • 8
  • 1
    System.Timers.Timer's Elapsed event swallows exceptions without a diagnostic, so not using try/catch is risky. And gives you a good reason. Running sndvol.exe is a simple way to regain volume control. – Hans Passant Jul 19 '22 at 22:23
  • Hey, I just tried this and I also added a try and catch, but the volume is still on 0 somehow... I also can't seem to run sndvol32.exe because HP (My Computer) Is overriding it with it's own audio controller. – omoor Jul 20 '22 at 07:00

1 Answers1

0

Turns out all I needed to do was set the volume value to 1... The value of the Music_Output.Volume is between 0 to 1 which is why it didn't work when I set it to 100; I also had to find that out by setting it to 100 on a different function and getting an error, credit goes to Hans Passant https://stackoverflow.com/users/17034/hans-passant for that.

omoor
  • 73
  • 8