Silverlight MediaElement Position Property Weirdness
Posted
by BarrettJ
on Stack Overflow
See other posts from Stack Overflow
or by BarrettJ
Published on 2010-06-17T21:42:34Z
Indexed on
2010/06/18
3:23 UTC
Read the original article
Hit count: 436
I have a MediaElement that is reporting its position incorrectly and weirdly, but consistently. It seems like when it gets to the last second of the audio (and it's always the last second, regardless if the sound is two seconds or 10), it doesn't update it's position until it finishes.
Example output:
Playback Progress: 0/3.99 - 0 Playback
Progress: 0.01/3.99 - 0 Playback
Progress: 0.03/3.99 - 0 Playback
Progress: 0.06/3.99 - 1 Playback
Progress: 0.07/3.99 - 1 Playback
Progress: 0.08/3.99 - 2 Playback
Progress: 0.11/3.99 - 2 Playback
Progress: 0.14/3.99 - 3 Playback
Progress: 0.19/3.99 - 4 Playback
Progress: 0.23/3.99 - 5 Playback
Progress: 0.25/3.99 - 6 Playback
Progress: 0.28/3.99 - 7 Playback
Progress: 0.3/3.99 - 7 Playback
[SNIP]
Playback Progress: 2.8/3.99 - 70
Playback Progress: 2.83/3.99 - 70
Playback Progress: 2.88/3.99 - 72
Playback Progress: 2.9/3.99 - 72
Playback Progress: 2.91/3.99 - 72
Playback Progress: 2.92/3.99 - 73
Playback Progress: 2.99/3.99 - 74
Playback Progress: 3/3.99 - 75
Playback Progress: 3/3.99 - 75
Playback Progress: 3/3.99 - 75
Playback Progress: 3/3.99 - 75
Playback Progress: 3/3.99 - 75
Playback Progress: 3/3.99 - 75
Playback Progress: 3/3.99 - 75
Playback Progress: 3/3.99 - 75
Playback Progress: 3/3.99 - 75
Playback Progress: 3.99/3.99 - 100
That is the result of:
WriteLine("Playback Progress: " + Position + "/" + LengthInSeconds + " - " + (int)((Position / LengthInSeconds) * 100));
public double Position
{
get
{
return my_media_element != null ? my_media_element.Position.TotalSeconds : 0;
}
}
public double LengthInSeconds
{
get
{
return my_media_element != null ? my_media_element.NaturalDuration.TimeSpan.TotalSeconds : 0;
}
}
Anyone have any ideas why this is occurring?
© Stack Overflow or respective owner