Question

I am trying to set the Media Elements position by following code:

MediaElement musicPlayer = new MediaElement();
musicPlayer.Position =  new TimeSpan(0, 0, 30);                        
musicPlayer.Source = new Uri(strMediaFileURL, UriKind.RelativeOrAbsolute);
LayoutRoot.Children.Add(musicPlayer);

To Surprise, musicPlayer.Position remains unchanged while debugging , any help please?

Thanks, Subhendu

Was it helpful?

Solution

Try it like this:-

MediaElement musicPlayer = new MediaElement();
musicPlayer.MediaOpened += (s, args) =>
{
    var player = (MediaElement)s;
    if (player.CanSeek)
        player.Position =  new TimeSpan(0, 0, 30);   
}                     
musicPlayer.Source = new Uri(strMediaFileURL, UriKind.RelativeOrAbsolute);
LayoutRoot.Children.Add(musicPlayer);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top