john john - 1 month ago 14
C# Question

C# - I have an issue with SoundPlayer

How to play two voice is conditional on the first timed

don't use thread and sync

SoundPlayer voice_1 = new SoundPlayer(Quran.Properties.Resources.voice_1);
SoundPlayer voice_2 = new SoundPlayer(Quran.Properties.Resources.voice_2);

private void textBox2_Click(object sender, EventArgs e)
{
//play this
voice_1.play();

//When Previous Finished

voice_2.play();
}

Answer

I too have read and conclusion If your meida use C # You can only play one song at a time But you can run the complete first track then went on to play the next song:

voice_1.PlaySnc ();

If you or track time to make use of this code.

Thread.sleep (1000);

But there is a problem too big in these two codes Which makes the sound be stopped by the end of the program to fix this problem must ==> await Async <== and use; process is used in Microsoft msdn site Good luck :)

private async void textBox1_Click(object sender, EventArgs e)
        {

                Voice_1.Play();

                await async_3s();

     public async Task<string> async_3s()
            {
                await Task.Delay(3000);
                return "Finished";
            }