Question

I am trying to pause a video on a specific location in my test code, and trying to start it from a totally different position. It eventually did start from the other point but when it pauses again, it moves back to the first instance it registered. I'd like to know what am I doing wrong in this code.

The code in CS file is

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();
   }

}

And the XAML code is

<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" />
Was it helpful?

Solution

If you want to jump to another position depending on the position where the video was stopped, your TimeSpan should be relative to this stop position, and not absolute:

If you want, say, jump over 10 seconds after the pause, that should be like that:

MediaElement.Position += TimeSpan.FromSeconds(10);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top