WPF MediaPlayer: How to play in sequence, sync?

前端 未结 2 574
生来不讨喜
生来不讨喜 2021-01-17 02:17

I have this function:

public static void Play(string FileName, bool Async = false)
    {
        System.Windows.Media.MediaPlayer mp = new System.Windows.Med         


        
2条回答
  •  滥情空心
    2021-01-17 02:46

    You need to wait for the current file to finish playing before calling Play on the next.

    This you do by listening for the MediaEnded event.

    You'll need to listen for the event:

    mp.MediaEnded += MediaEndedEventHandler;
    

    However, you'll need to make the MediaPlayer object a static too so you only ever have one of them. Make sure you only add this handler the once. Then in the handler issue a new event to start playing the next file.

    What you are implementing is a playlist. So you'll add the files to the playlist and then you'll need to keep a track of your current position in the playlist.

提交回复
热议问题