开发者

WP7 MediaElement Unable to Reposition the stream

开发者 https://www.devze.com 2023-04-09 00:02 出处:网络
I am using MediaElement for video playback in my app. I have added controls for play, pause, rewind and forward. In the forward button\'s event handler, I am trying to forward the video clip f开发者_高

I am using MediaElement for video playback in my app. I have added controls for play, pause, rewind and forward. In the forward button's event handler, I am trying to forward the video clip f开发者_高级运维or 5 seconds. the code I have used to do that is given below.

if(myMediaElement.CanSeek)
{
    myMediaElement.Position = TimeSpan.FromSeconds(2);
    myMediaElement.Play();
}

But the video clip does not forward, instead it stops the video playback. Can anyone please tell me what is going wrong.


You need to start playing the stream before you can set the position.

Move the call to CanSeek and the setting of the position until after the MediaOpened event has been raised.

See the remarks in MSDN http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement.position(v=VS.95).aspx for confirmation.


Using valueconverter sample here, with Slider adjustments, to get the positions http://diggthedrazen.com/2011/07/08/using-an-ivalueconverter-to-create-a-player-with-a-seek-bar-on-windows-phone/

0

精彩评论

暂无评论...
验证码 换一张
取 消