C# SoundPlayer not working properly when put after Console.ReadLine()

420 views Asked by At

I have a very simple console application where I'm trying to play a wav file with SoundPlayer.

static void Main(string[] args)
{
    SoundPlayer sp = new SoundPlayer("path/to/sound.wav");

    while(true){
        Console.ReadLine();
        sp.PlaySync();
    }
}

It works fine except when PlaySync() is right after Console.ReadLine(). It seems the longer I wait before putting an input, the lower the volume of the sound.

I have tried using sp.Play() (the asynchronous version) and I have tried putting a Thread.Sleep() delay between them. There was no difference. What could be the cause of this?

(This is my first post here so forgive my mistakes)

1

There are 1 answers

0
Simon M. On

The answer is as simple as the question. Use Stop() every time PlaySync() is called.