WPF:播放视频文件的一部分

时间:2013-08-28 13:50:56

标签: c# wpf video timer

我正在尝试一次使用MediaElement控件播放一个.wmv。

我正在使用计时器播放/暂停视频

但视频播放一直不同步。

有任何想法如何解决这个问题?

public partial class MainWindow : Window
{
    private System.Windows.Threading.DispatcherTimer VideoTimer;
    private bool is_playing;

    private void PlaySegment(long duration_miliseconds,long offset_milisecond=-1)
    {
        if (is_playing) return;
        VideoTimer.Interval = new TimeSpan(10000*duration_miliseconds);
        is_playing = true;
        if (offset_milisecond>=0)
            VideoControl.Position = new TimeSpan(10000*offset_milisecond);
        VideoControl.Play();
        VideoTimer.Start();
    }
    private void Timer_Stopped(object sender, EventArgs e)
    {
        VideoControl.Pause();
        is_playing = false;
    }
    public MainWindow()
    {
        InitializeComponent();
        VideoTimer = new System.Windows.Threading.DispatcherTimer();
        VideoTimer.Tick += new EventHandler(Timer_Stopped);
    }
}

这是相关的XAML代码: <MediaElement x:Name="VideoControl" LoadedBehavior="Manual" />

谢谢!

1 个答案:

答案 0 :(得分:1)

开启擦洗......

VideoControl.ScrubbingEnabled = true;