WPF SoundPlayer multichannel audio?
I have an application that emits sounds at an arbitrary interval. When two sounds collide, they do not replay each other beautifully, but one interrupts the other.
I am using SoundPlayer to play sounds. (this is a WPF app)
How can I use multiple audio channels so that when two sounds are playing at the same time, they play at the same time and not interrupt the other?
source to share
As far as I know, SoundPlayer
uses the built-in PlaySound feature which doesn't support playing multiple sounds at the same time.
However, you can do it with System.Windows.Media.MediaPlayer
.
var p1 = new MediaPlayer();
p1.Open(new Uri(@"C:\windows\media\ringout.wav"));
p1.Play();
System.Threading.Thread.Sleep(250);
var p2 = new MediaPlayer();
p2.Open(new System.Uri(@"C:\windows\media\ringout.wav"));
p2.Play();
Sleeping just adds a bit of delay to the playback, making it clear that both sounds are indeed playing at the same time.
source to share