Skip to main content

Microsoft Silverlight

Answered Question MediaElement seek (position) issueRSS Feed

(0)

N37-L0RD
N37-L0RD

Member

Member

1 points

2 Posts

MediaElement seek (position) issue

Hello!

I have a very strange problem.

I'm loading a video in silverlight from a web server (i also tried silverlight streaming) and it all works well. I have an indicator of "already downloaded" (via DownloadProgress) and i use a slider overlayed with a rectangle (mouse events) to do the navigation.

The problem appears when i try to seek to a different position in the movie (the one WHO I'VE ALREADY SEEN - is downloaded). Click events are OK, time calculations are also fine (slider moves to the right spot, seconds are accurate), but when i do this:

 

this.moviePlayer.Position = TimeSpan.FromSeconds(s);
 

...movie simply stops and "freezes".

It's also interesting that it somehow works well in a short movie (5-10 sec).

Any ideas how to fix this? Tnx in advance.

brucechase
brucechase

Member

Member

78 points

31 Posts

Re: MediaElement seek (position) issue

I have a very similar problem.  The problem is much more acute with low-quality FLV files transcoded to WMV files.  The original FLV files may have been at 15 frames per second as a guess (I have not checked).  When high-quality video files taken from MPG4 or MOV are encoded to WMV format with about 30 frames per second, the use of MediaElement.Position is a bit better.  The Position works somewhat well if I position the video ahead by just hundredths of a second (let's say, about 1 frame) but Position does not work well in moving backward unless the increment is greater than 1 second. 

I am playing with all types of techniques.  I have repostioned the video backward a few seconds and then put a dynamic timeline marker into the Markers collection at the point where I want the video to stop (let's say 6 hundredths of a second behind where I am) and played the video up to the point of the marker for which the Marker callback comes into play.  Within the callback, I stop the video.  The position should be right?  Nope.  The Marker referenced by the marker callback is actually 0.04 seconds late.  That is, the callback is finally used 0.04 (and up to 0.1) seconds after the position is hit by the media element. Now that may not seem like much and relative to streaming content, it is not.  But it proves the difficulty in using all types of hacks in order to zero in on a specifc position within a video.  Even though the documentation speaks of how extremely fine-grained the Position is, the reality is one cannot align the actual video content with the Position.  If one steps back in the video in 0.05 hundreds a second increment, the video frame may not change for up to 2 or 3 seconds of step-backs. 

If I find a solution to this, I will let you know.

visuallook
visuallook

Member

Member

60 points

10 Posts

Answered Question

Re: MediaElement seek (position) issue

Hello N37,

Try this.. 

 

moviePlayer.MediaOpened += new RoutedEventHandler(moviePlayer_MediaOpened);

 

void mediaPlayer_MediaOpened(object sender, RoutedEventArgs e)

{

mediaPlayer.Position = TimeSpan.FromSeconds(s);

mediaPlayer.Play();

}

 

;)

 

Pravesh Khatana
Creative Designer
Web: http://www.khatana.in/

"Please remember to mark the replies as answers if they help and unmark them if they provide no help."

brucechase
brucechase

Member

Member

78 points

31 Posts

Re: MediaElement seek (position) issue

My problem is a bit different than the problem of seeking an exact position upon the opening event.  My problem is to get to a somewhat exact position (let's say within a 10th of a second) after the video has played.  Within sports video, one may want to move forward and backward at small increments when replaying an event on the video. Silverlight does a fine job of seeking an exact position when moving forward quote, unquote, "frame by frame."  The problem I have is stepping backward in a video.  When seeking a position, the Get part of the Position function returns a timespan that does not at all match the display.  In stepping back in the video, the display may not change for 2 seconds of incremental step-back of say, 20 x 0.1 seconds.  Then suddenly, the video displays 2 seconds prior to the original Position. 

This only occurs on lower quality videos that are encoded by FFMPEG from FLV files to WMV (so far).  Those videos files have a framerate of 29.97 fps.

You can see the problem at:

http://www.CoachMeSports.com?xamlID=325d4256-f5e4-4f61-a493-df3387ecda60

(The small "+" and "-" buttons on the video player allow one to step forward and backward in small steps, respectively.)

Another video, encoded from a MOV file to WMV (via Microsoft's Expression Encoder) does not display the same problem:

http://www.CoachMeSports.com?xamlID=17b66798-07c3-4592-aead-64e746499a67

So, it appears that Silverlight handles the display of a video frames relative to the Position call differently depending upon the video source when moving backward in the video. 

This does not make or break an appliction. It is an annoyance.

brucechase
brucechase

Member

Member

78 points

31 Posts

Re: MediaElement seek (position) issue

An update for those that find the Position call does not cause a proper display update within Silverlight.. 

On further testing, I have found a way to get the MediaElement.Position to work correctly on most videos.  If the original source of the video is MP4 for instance, and Expression Encoder cannot transcode the video to WMV format, I have had my Window's service use FFMPEG to do the transcoding.  The resulting files play within Silverlight, but the Position call does not correctly update the display to the Position's returned timespan.  But, if the transcoded WMV file (from FFMPEG) can then be put through Microsoft's Expression Encoder and the resulting output (again, a WMV as well) will play correctly (as the original WMV file did) but a call to the Position function actually causes a screen update such that the video display and the Position call match.

I find that nearly all the uploaded files to our site are not Expression Encoder compatible because nearly all are MP4 or a variation thereof.  The MOV files do encode correctly within Expression Encoder, but under 64-bit Windows Server 2003, it takes a little bit to get the correct codecs installed -- at least for us novices.

So, encode with FFMEG to WMV and take the results and encode with Expression Encoder to WMV again.

MarauderzMY
MarauderzMY

Member

Member

607 points

265 Posts

Re: Re: MediaElement seek (position) issue

Here's what I did for my download progress.

Like what you did, I decided to track when was the furthest played portion of the video. only thing is that I track at the MILISECOND scale, which I think offers a bit more granular than just using seconds.

Also, when dealing with non fully downloadable videos, instead of diirectly jumping to the furthest played position, I always back up about a second. I know it might not be what you want to hear since you need EXACT video movement. but might be able to give you some ideas.

N37-L0RD
N37-L0RD

Member

Member

1 points

2 Posts

Re: MediaElement seek (position) issue

I changed visuallook's fix to fit my application and it actually solved the problem. I can now change position without any issues.

visuallook
visuallook

Member

Member

60 points

10 Posts

Re: Re: MediaElement seek (position) issue

hi N37,

sorry for the last one ;)

 

moviePlayer.MediaOpened += new RoutedEventHandler(moviePlayer_MediaOpened);

 

void moviePlayer_MediaOpened(object sender, RoutedEventArgs e)

{

moviePlayer.Position = TimeSpan.FromSeconds(s);

moviePlayer.Play();

}

 

 

Pravesh Khatana
Creative Designer
Web: http://www.khatana.in/

"Please remember to mark the replies as answers if they help and unmark them if they provide no help."

dmacdonald
dmacdonald

Member

Member

22 points

17 Posts

Re: Re: MediaElement seek (position) issue

 I'm sorry I'm a little confused. I'm having a similar issue, I'm trying to manually control playback of some h264 encoded video by setting the position manualyl within a timer (or a scrub bar). I have several seconds lag between any manual setting of the position and the video display actually updating. I dont understand your fix either visuallook (and it didnt seem to help me). Can you guys clarify?

Thanks,


Daniel

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities