当用户点击'播放'按钮时,我的程序应该播放视频。然而,“Play”的第一次点击却什么都不做。'MediaElement.CurrentState'由于未知原因而变为'Closed'
该代码,这是非常简单的,它只是调用我的MediaElement,录像机“的SetSource”,然后播放:
private async void playVideo_Tapped(object sender, TappedRoutedEventArgs e)
{
await setUpVideo();
VideoPlayer.Play();
}
我经历过“setUpVideo()”多次,那里的一切像它应该那样工作,在确定文件存在后它只调用'VideoPlayer.SetSource()'。但直到我在一个方法抛出监控“VideoPlayer.CurrentState”,我才意识到了问题的状态:
public VideoViewer()
{
this.InitializeComponent();
VideoPlayer.CurrentStateChanged += VideoPlayer_CurrentStateChanged;
}
void VideoPlayer_CurrentStateChanged(object sender, RoutedEventArgs e)
{
var foo = VideoPlayer.CurrentState;
}
如果我检查“富”,而我的代码运行我看到的价值在'playVideo_Tapped()'完成后,第一次轻敲(并且只有第一次轻敲)'VideoPlayer.CurrentState'变为'Opening',然后变回'Closed'!之后的每一次敲击都会按照'打开'到'播放'然后'已暂停'的正确顺序进行,但第一次敲击总是会关闭。为什么是这样??