您可以使用SoundPlayer.PlaySync()
起着使用用户界面线程,这样wowSound
将首先播放的.wav
文件。然后,countingSound
将wowSound
后播放播放完毕
例
SoundPlayer wowSound = new SoundPlayer(@"soundEffect/Wow.wav"); //Initialize a new SoundPlayer of name wowSound
SoundPlayer countingSound = new SoundPlayer(@"soundEffect/funny.wav"); //Initialize a new SoundPlayer of name wowSound
wowSound.PlaySync(); //Play soundEffect/Wow.wav synchronously
countingSound.PlaySync(); //Play soundEffect/funny.wav synchronously
注意:在同一时间使用SoundPlayer
不能多打一个声音,因为它不支持播放同步声音。如果你想一次演奏两个或更多的声音,System.Windows.Media.MediaPlayer
会是一个更好的选择
例
MediaPlayer wowSound = new MediaPlayer(); //Initialize a new instance of MediaPlayer of name wowSound
wowSound.Open(new Uri(@"soundEffect/Wow.wav")); //Open the file for a media playback
wowSound.Play(); //Play the media
MediaPlayer countingSound = new MediaPlayer(); //Initialize a new instance of MediaPlayer of name countingSound
countingSound.Open(new Uri(@"soundEffect/funny.wav")); //Open the file for a media playback
countingSound.Play(); //Play the media
http://www.interact-sw.co.uk/iangblog/2008/01/25/wpf-concurrent-audio ..我看到这一个,但没有尝试.. – Mullaly
这是因为你喜欢派对? – WildCrustacean