È possibile utilizzare SoundPlayer.PlaySync()
che svolge il file .wav
utilizzando il filo interfaccia utente in modo che wowSound
sarebbe giocato prima. Poi, countingSound
si giocherà dopo wowSound
ha finito di giocare
Esempio
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
AVVISO: Non si può giocare più di un suono allo stesso tempo utilizzando SoundPlayer
in quanto non supporta la riproduzione simultanea suoni. Se si desidera riprodurre due o più suoni contemporaneamente, System.Windows.Media.MediaPlayer
sarebbe una scelta migliore
Esempio
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
fonte
2012-12-18 03:35:49
http://www.interact-sw.co.uk/iangblog/2008/01/25/wpf-concurrent-audio .. Ho visto questo, ma non l'ho provato .. – Mullaly
È questo perché ti piace festeggiare? – WildCrustacean