how to play video using mediaElement in wpf?

How to cyclically play video from one position to another using MediaElement in WPF

  • I am using WPF mediaelement for playing video. What I need is to cyclically play a video form x position to y position. Is there any way to achieve this without using timer and polling Position property?

  • Answer:

    You don't have to poll the position property, but you can set it to begin play at start position, start a timer and set the interval for the time difference. TimeSpan startTime = TimeSpan.FromSeconds(45); TImeSpan endTime = TimeSpan.FromSeconds(55); int timeDifference = endTime.TotalSeconds - startTime.TotalSeconds; mediaElement.Position = startTime; Timer t = new Timer() { Interval = timeDifference * 1000, AutoReset = true }; t.Tick += (sender, e) { mediaElement.Position = startTime }; t.Start();

Peter17 at Stack Overflow Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.