I use SoundPlayer to play sound effects in the WPF program. However, I find that when two sounds effects are played at the same time, the new one will replace the old one (i.e. the new will terminate the old and play itself), but what I want is to keep playing the old one even when the new one is played.
SoundPlayer wowSound = new SoundPlayer("soundEffect/Wow.wav");
SoundPlayer countingSound = new SoundPlayer("soundEffect/funny.wav");
wowSound.Play(); // play like background music
countingSound.Play(); // from click to generate the sound effect
You may use
SoundPlayer.PlaySync()which plays the.wavfile using the User Interface thread so thatwowSoundwould be played first. Then,countingSoundwill be played afterwowSoundhas finished playingExample
NOTICE: You can not play more than ONE sound at the same time using
SoundPlayeras it does not support playing simultaneous sounds. If you would like to play TWO or more sounds at once,System.Windows.Media.MediaPlayerwould be a better optionExample