Adjusting timeline length

Topics: Windows 8 Xaml
Sep 25, 2012 at 12:31 PM

Hi,

I need to adjust the timeline so it corresponds to a specific time in a stream.

I can easily adjust the start time using the following code:

 

var startupPosition = new TimeSpan(0, 0, (int)asset.OnDemandTimeBegin);
mediaPlayer.StartTime = startupPosition;
mediaPlayer.StartupPosition = startupPosition;

 

But I can't seem to find the right properties to adjust the end of the timeline and to stop the video. The following code seems to have no effect:

endPosition = new TimeSpan(0, 0, (int) asset.OnDemandTimeEnd);
mediaPlayer.EndTime = endPosition;

And there is no EndPosition property. Any solutions out there?

Regards

Coordinator
Sep 26, 2012 at 2:01 AM

EndTime is automatically set by the duration coming from the MediaElement when the media is opened. I believe if you set it yourself from MediaOpened it will overwrite this default value. Please give this a shot and let me know if it does not work for you, Tim

Oct 9, 2012 at 10:43 AM
timgreenfield wrote:

EndTime is automatically set by the duration coming from the MediaElement when the media is opened. I believe if you set it yourself from MediaOpened it will overwrite this default value. Please give this a shot and let me know if it does not work for you, Tim


Hi tim

I had a similar requirement and have tried out setting the ENDTIME property in the MediaOpened event. It doesn't work. Tried to check setting the Duration property, it doesn't work as it says it is a read-only property. Strangely the duration property tooltip indicates "Gets or sets duration of the current video or audio.".

Any help on this

Coordinator
Oct 10, 2012 at 11:54 PM

keesarisrikanth, are you using progressive or smooth streaming? I just tried this out with a progressive download and the timeline is affected by the new EndTime value. For example:

public ProgressivePage()
{
    this.InitializeComponent();
    player.MediaOpened += player_MediaOpened;
}

void player_MediaOpened(object sender, RoutedEventArgs e)
{
    player.EndTime = TimeSpan.FromMinutes(2);
}

Smooth streaming is another matter because the EndTime is continually updated during playback. This is due to the fact that the dvr window can change during live playback.

Also, thanks for letting me know about the incorrect code comment; the property is supposed to be readonly.