我试图通过以下代码设置媒体元素位置:
MediaElement musicPlayer = new MediaElement();
musicPlayer.Position = new TimeSpan(0, 0, 30);
musicPlayer.Source = new Uri(strMediaFileURL, UriKind.RelativeOrAbsolute);
LayoutRoot.Children.Add(musicPlayer);
令人惊讶的是,在调试时,musicPlayer.Position保持不变,有什么帮助吗?
谢谢,
Subhendu
最佳答案 试试这样: –
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);