views:

477

answers:

1

Hi, 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

+1  A: 

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);
AnthonyWJones
It Works, Thanks a Lot :)
Subhen