I have this function:
public static void Play(string FileName, bool Async = false)
{
System.Windows.Media.MediaPlayer mp = new System.Windows.Media.MediaPlayer();
mp.Open(FileName.ToUri());
mp.Play();
}
When i call
Play(@"file1.mp3");
Play(@"file2.mp3");
Play(@"file3.mp3");
Play(@"file4.mp3");
all them play at same time.
How can i make MediaPlayer wait the end of the file, to play the next? What the function should like?
EDIT:
public static void Play(Uri FileName, bool Async = false)
{
AutoResetEvent a = new AutoResetEvent(false);
MediaPlayer mp = new MediaPlayer();
mp.MediaEnded += (o1, p1) =>
{
a.Set();
};
mp.MediaOpened += (o, p) =>
{
int total = Convert.ToInt32(mp.NaturalDuration.TimeSpan.TotalMilliseconds);
mp.Play();
if (!Async)
{
//System.Threading.Thread.Sleep(total);
a.WaitOne();
}
};
mp.Open(FileName);
}
I will share my Solution with you:
I created a Window: WindowPlay.xaml
WindowPlay.xaml.cs: