NAudio - WaveOutEvent.Volume Muted my entire game and I CANNOT revert it

397 Views Asked by At

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?

1

There are 1 best solutions below

0
omoor On

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.