locked
MediaElement position, timeline slider issue RRS feed

  • Question

  • Hello,

    I have a media element with a timeline slider.
    The requirement is such that the slider should change its value as the video plays and also if I change the slider by dragging it then video's position should also be changed.

    So I have implemented a dispatcher timer with an interval of 100ms and in its tick event, i am setting the slider value to Mediaelement.Position.TotalMilliseconds.
    this works fine and the slider moves in sync with the video.

    Now for the other requirement in which the user can change the slider by dragging, i have implemented a Slider.valuechange event, in this event I am setting the Mediaelement position to the slider value.


    Now if you see, i have a problem here,.....when my timer ticks the slider value is changed to the mediaelement position which in turn fires the Slider.ValueChange event which again sets the media element position to the slider value.
    So this loop keeps on going and my video doesn't play smoothly.

    Can anyone suggest me how to tackle this problem and implement both the desired features?


    P.S. i tried using the timeline approach but there also I m not able to achieve both the features


    Cheers,
    Sumit


    Sunday, December 20, 2009 7:42 PM

Answers

  • Hi Sumit,

    I haven't done anything with videos yet, but I recall having seen this sort of question a couple of times already. Have you searched the forum (try google with "site:social.msdn.microsoft.com wpf media player slider")? Also, Sacha Barber has published a Media Player article on the CodeProject that comes with a (seek-) slider. Give it a shot, maybe it gives you what you're after ...
    Cheers,
    Olaf
    Monday, December 21, 2009 6:34 PM

All replies

  • Anyone?
    Monday, December 21, 2009 7:57 AM
  • Hi Sumit,

    I haven't done anything with videos yet, but I recall having seen this sort of question a couple of times already. Have you searched the forum (try google with "site:social.msdn.microsoft.com wpf media player slider")? Also, Sacha Barber has published a Media Player article on the CodeProject that comes with a (seek-) slider. Give it a shot, maybe it gives you what you're after ...
    Cheers,
    Olaf
    Monday, December 21, 2009 6:34 PM
  • I know this is an old thread, but for anyone else who have hit this problem, the jerky video playback when trying to maintain the position in a slider of the current position in a video might be because you have mixed up your seconds and milliseconds.

    If you use a timer and set its interval to TimeSpan.FromMilliseconds(1000) then you must, throughtout, set the slider's maximum and current position to TotalMilliseconds as well (not TimeSpan.FromSeconds).

    The examples I found to do this seem to mix up milliseconds and seconds, and the media element doesn't seem to like this.

    I hope this helps someone.

    Tony 

    • Proposed as answer by Tony Vaughan Thursday, June 21, 2012 1:47 PM
    • Edited by Tony Vaughan Thursday, June 21, 2012 1:56 PM
    Thursday, June 21, 2012 1:18 PM