2012-10-20 90 views
0

我试图在新线程中播放声音,以便在播放时其他声音不会中断它。线程不在后台运行

但它不起作用。虽然新线程在后台运行(我假设),但后来播放的声音会中断它。

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(); 
} 

我想在不中断对方的情况下播放各种声音。

+0

你读过这个问题吗? http://stackoverflow.com/questions/6240002/play-two-sounds-simultaneusly – Fabske

+0

不适合silverlight – QKL

回答

1

我认为你不需要使用线程。您可以在某个时刻拥有16个SoundEffectInstances。这不够吗?

检查this example

他们只是持有三个SoundEffect实例。

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

并通过某些事件播放它们。

+0

这真的有窍门! – QKL