您可以使用SoundPlayer.PlaySync()
which.wav
使用用户界面线程播放文件,以便wowSound
首先播放。然后,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