wpf media元素在第一次按键单击时不播放视频

时间:2014-08-08 09:02:50

标签: c# wpf video

我有一个带有mediaelement控件的WPF应用程序用于视频播放。这是2GB MJPEG编码,avi容器视频。在做了一些小的研究(谷歌搜索)后,我发现我需要检查媒体元素是否具有视频的时间跨度才能实际播放。当用户第一次点击按钮播放时;视频无法播放,但点击按钮三次后,即可播放。

private void playPauseVideoButton_Click(object sender, RoutedEventArgs e)
{
    if (tag == "1")
    {
        flagFrameCapture = false;               //if video is playing then no need to allow user capture anything
        fOnly = false;
        fullFrameRadioButton.IsChecked = false;
        countClickFrameCapture = 0;             //assign 0 to use it as a flag to determine if the frame has been saved or not
        playPauseVideoButton.Tag = "2";         //determines if the video is paused or playing
        saveButton.IsEnabled = false;           //disable button save
        DisableRadioButtons();                  //disable the radio button
        flagRectangle = false;                  //flag that we are playing a video
        flagEllipse = false;
        CapturedFullImage.Visibility = System.Windows.Visibility.Collapsed; //make Image component invisible
        //RemovePins();
        //LoadingAdorner.IsAdornerVisible = !LoadingAdorner.IsAdornerVisible;

        //LoadingAdorner.IsAdornerVisible = !LoadingAdorner.IsAdornerVisible;

        if (playVideoMediaElement.NaturalDuration.HasTimeSpan)              //check that the video has not reached the end
        {
            playVideoMediaElement.Play();               //play the video
            InitialiseSliderAndTimer();                                           //default the video slider and timer
            ChangePlayPauseButtonImageIcon();           //changes the image icon of the button to pause icon
            IsPlaying(true);                            //method enables or disables the buttons
            IsPaused(true);                             //enable the fast and slow palay buttons
        }
    }
}

有谁知道这是为什么?

0 个答案:

没有答案