0

I am trying to play a sound in a new thread, so that other sounds don't interrupt it, while it is playing.

But it doesn't work. Although the new thread runs in background (I assume), the sounds which are played afterwards interrupt it.

ParameterizedThreadStart pts;
        Thread t;

private void playStreak(Object p)
        {
            SoundEffect sound = SoundEffect.FromStream(Application.GetResourceStream(new Uri("SOUNDFX/BOMB.wav", UriKind.Relative)).Stream);
            SoundEffectInstance instance = sound.CreateInstance();
            instance.Play();
        }

private void playAsThread()
{
     pts = new ParameterizedThreadStart(playStreak);
     t = new Thread(pts);
     t.Name = "Streak sound!";
     t.Start();
}

I want to play various sounds without interrupting each other.

Anton Sizikov
  • 9,105
  • 1
  • 28
  • 39
QKL
  • 259
  • 1
  • 3
  • 11
  • Dis you read this question ? http://stackoverflow.com/questions/6240002/play-two-sounds-simultaneusly – Fabske Oct 20 '12 at 11:09

2 Answers2

1

I think you don't need to use threads. You can have 16 SoundEffectInstances at one moment. Isn't it enough?

Check this example.

They just hold three SoundEffect instances.

    private SoundEffect coyoteSound;
    private SoundEffect birdSound;
    private SoundEffect ambienceSound;

and play them by some event.

Anton Sizikov
  • 9,105
  • 1
  • 28
  • 39
0

If you do need to use thread, use BackgroundWorker. It's nice and easy!

Jason94
  • 13,320
  • 37
  • 106
  • 184