Silverlight media player position problem
Asked Answered
I

2

6

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?

Irma answered 24/11, 2010 at 5:5 Comment(3)
You are certain that the wrong frame is being shown, That there isa frame at 200ms and another at 199ms?Swill
actually am more concern how 04:40:00.2000000 was converted to 04:40:00.1990000 ??Irma
This could also be due to the particular codec being used for playback only being able to position to a frame start. In some work I am doing I have a codec that can only position to a Key Frame (which in my case causes positioning to be off by up to a whole second). I deal with it by making the rest of my interface react to where the player says I am, even after telling it where I want to go.Villegas
S
3

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.

Superlative answered 16/3, 2011 at 4:28 Comment(1)
That was my assessment as well, the property for the Video Player is showing the time signature for the current frame, it won't necessarily be the same as the time-span you pass into it, because there might not be a frame starting at that exact millisecond.Constitutional
F
1

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.

Fortner answered 24/11, 2010 at 10:21 Comment(1)
It is stored in an Int64 as ticks, and converted to/from as needed.Villegas

© 2022 - 2024 — McMap. All rights reserved.