Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在WPF和C中暂停视频并从另一个位置播放#_C#_Wpf_Xaml_Mediaelement_Dispatchertimer - Fatal编程技术网

C# 如何在WPF和C中暂停视频并从另一个位置播放#

C# 如何在WPF和C中暂停视频并从另一个位置播放#,c#,wpf,xaml,mediaelement,dispatchertimer,C#,Wpf,Xaml,Mediaelement,Dispatchertimer,我尝试在测试代码中的特定位置暂停视频,并尝试从完全不同的位置开始。它最终确实从另一个点开始,但当它再次暂停时,它会移回它注册的第一个实例。我想知道我在这段代码中做错了什么 CS文件中的代码是 namespace timer_thread_and_gui { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Wind

我尝试在测试代码中的特定位置暂停视频,并尝试从完全不同的位置开始。它最终确实从另一个点开始,但当它再次暂停时,它会移回它注册的第一个实例。我想知道我在这段代码中做错了什么

CS文件中的代码是

namespace timer_thread_and_gui
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
        DispatcherTimer timer;
        DispatcherTimer timer1;


    public MainWindow()
    {
        InitializeComponent();

   }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        timer1 = new DispatcherTimer();
        timer1.Tick += new EventHandler(dispatcherTimer_Tick1);
        timer1.Interval = new TimeSpan(0, 0, 10);

                    timer = new DispatcherTimer();
                    timer.Tick += new EventHandler(dispatcherTimer_Tick);
                    timer.Interval = new TimeSpan(0, 0, 5);
                    video_panel.Play();




            timer1.Start();
            timer.Start();




    }

    private void dispatcherTimer_Tick(object sender, EventArgs e)
    {
        this.draw_an_elipse();

       draw_an_elipse()
    {
       ++a;
       txt.Text = a.ToString();



       if (a%5==0)
       {
           video_panel.Stop();
           video_panel.Position = new TimeSpan(0, 18, 30);

           video_panel.Play();
           timer1.Start();
       }
    }

   private void dispatcherTimer_Tick1(object sender, EventArgs e)
   {

    video_panel.Pause();
    timer1.Stop();
   }

}
名称空间计时器线程和gui
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
调度定时器;
调度员定时器1;
公共主窗口()
{
初始化组件();
}
已加载私有无效窗口(对象发送器、路由目标)
{
timer1=新的调度程序();
timer1.Tick+=新事件处理程序(dispatcherTimer_Tick1);
timer1.Interval=新的时间跨度(0,0,10);
计时器=新调度程序();
timer.Tick+=新事件处理程序(Dispatcher_Tick);
timer.Interval=新的时间跨度(0,0,5);
视频_面板。播放();
timer1.Start();
timer.Start();
}
私有void Dispatcher_Tick(对象发送方,事件参数e)
{
这个。画一个椭圆();
画一个伊莱普()
{
++a;
txt.Text=a.ToString();
如果(a%5==0)
{
视频_面板。停止();
video_panel.Position=新的时间跨度(0,18,30);
视频_面板。播放();
timer1.Start();
}
}
私有无效Dispatchermer_Tick1(对象发送方,事件参数e)
{
视频_面板。暂停();
timer1.Stop();
}
}
XAML代码是

<MediaElement Height="266" HorizontalAlignment="Left" Margin="12,33,0,0" Name="video_panel" 
                  VerticalAlignment="Top" Width="474" 
                  LoadedBehavior="Manual" UnloadedBehavior="Stop" 
                  Source="c:\users\ayymmoo\documents\visual studio 2010\Projects\Unfinished.avi" />

如果您想根据视频停止的位置跳转到另一个位置,您的时间跨度应该是相对于该停止位置的,而不是绝对的:

如果你想,比如说,在暂停10秒后跳转,那应该是这样的:

MediaElement.Position += TimeSpan.FromSeconds(10);

非常感谢。效果很好。但还有一件事我想知道。如果我想回到一个职位上怎么办?有什么东西可以让我相对于当前时间倒退吗?