views:

115

answers:

1

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?

+2  A: 

The Position property in Silverlight has a "clamping" effect that can cause this, to prevent seeking to say the last 1s of content.

Unfortunately there's no easy fix AFAIK.

Jeff Wilcox
Out of curiosity, why would it be desirable to prevent seeking to the last 1s of content? Further, why would they code it such that the getter clamps as well and not just the setter? Not sure if you know the answers, but this seems like such odd behavior and I can't wrap my head around the why.
BarrettJ
I believe it has to do with a Slider scenario where you have a media player. I only am sharing what I understand and unfortunately it's not complete.
Jeff Wilcox