c# WPF how to repeat MediaElement playback from mediaended event handler without declaring new source?

前端 未结 5 1061
Happy的楠姐
Happy的楠姐 2020-12-18 00:23

I\'m playing a video in WPF.i want it to loop so what I did is when the mediaended event fires, I play back my video. so this will get me a loop. prob is why do u I have to

5条回答
  •  清酒与你
    2020-12-18 01:16

    Instead of resetting the Source at the start of your Media_Ended handler, try setting the Position value back to the start position. The Position property is a TimeSpan so you probably want something like...

    private void Media_Ended(object sender, EventArgs e)
    {
        media.Position = TimeSpan.Zero;
        media.Play();
    }
    

提交回复
热议问题