Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight media player position problem

I'm facing a strange issue. My application plays movies from specific positions, so even a position mentioned in milliseconds matters for me. I'm assigning a position to a media element but it's showing the wrong frame. I don't know why media player is not playing from the position that I'm giving.

Here is some sample code:

 TimeSpan oTimeSpan = TimeSpan.FromMilliseconds(16800200); // This shows 04:40:00.2000000

 MediaPlayer.Position = oTimeSpan;      // But after assigning, value is 04:40:00.1990000

Here is a screenshot before and after assigning: alt text

alt text

Can anybody tell me what I'm doing wrong here?

like image 867
Singleton Avatar asked Nov 24 '10 05:11

Singleton


2 Answers

While you maybe concerned about the fractional milliseconds difference in this case, you have to remember that video is only going to have a frame every ~33 milliseconds or so (using standard NTSC 29.97 FPS). So unless you are doing forensics level analysis(in which case MediaPlayer is not the right tool), that is more accuracy than you should need.

Since a TimeSpan uses Int64 internally and therefore should not have any rounding issues, my guess is that MediaPlayer is snapping to the closest video frame available.

like image 76
Brent Stewart Avatar answered Nov 04 '22 03:11

Brent Stewart


Although timespan exposes it's properties as ints I suspect that it's using a floating point value internally. Such issues are due to the way floating point values are stored.

Have you tried checking what you get from TimeSpan.Equals(MediaPlayer.Position, oTimeSpan)? I suspect this would indicate that they are equal.

like image 1
Matt Lacey Avatar answered Nov 04 '22 03:11

Matt Lacey