How to play an Audio File After another has Finished in WPF MediaElement

Posted by Vuyiswamb under WPF on 1/4/2013 | Points: 10 | Views : 1535 | Status : [Member] [MVP] [Administrator] | Replies : 0
Good Day

i have a Media Element in WPF and i am playing mp3's programatically on a click of a button. Now there are times where i want to Play two different mp3's in an order after another e.g



PlayAudio("AccountOpen_Message1");

PlayAudio("AccountOpen_Message2");

Now i tried to put it a Thread Sleep between, it work once after that the Second mp3 plays after the first one. So i want to call the same function twice to play different mp3's but i want one to wait for another to finish playing before playing, i hoped for a "isPlaying" Property to determine if the element was playing. Does anyone have a solution.





     //Function to Play a Video
private void PlayAudio(string Fruit)
{
VideoPlayer.Source = new Uri(@"D:\Articles\How to identify Players in Kinect\IdentifyPlayers\WpfApplication1\WpfApplication1\Voices\" + Fruit + ".mp3", UriKind.Absolute);
VideoPlayer.LoadedBehavior = MediaState.Manual;
VideoPlayer.Play();
}

 <MediaElement x:Name="VideoPlayer"  Volume="100" LoadedBehavior="Manual" MediaEnded="VideoPlayer_MediaEnded"  UnloadedBehavior="Close"   ></MediaElement>



   private void VideoPlayer_MediaEnded(object sender, RoutedEventArgs e)
{
this.Close();
}





Thanks

Thank you for posting at Dotnetfunda
[Administrator]



Responses

(No response found.)

Login to post response