locked
FastForward Button does rather odd things! :( RRS feed

  • Question

  • Hello!

    I have a video inside a child window. With a series of buttons controlling the video, Stop Pause and Play work with no problems.  I've put in the following code which will allow the user to fastforward through the video. Unfortunatly it does work quite right. When the fast forward button is selected the video simply stops and returns to the beginging, when you hit it again, it loops around for the first 3 seconds. Im new to all this, and i cant figure out whats going on!

    I was hoping someone would help me! :(

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Windows.Threading;

    namespace PhNewAttempt
    {
        public enum PlayRate
        {
            Normal,
            X1FF,
            X2FF,
        }

        public partial class ChildVideo1 : ChildWindow
        {
            private DispatcherTimer _PlayTimer;
            private PlayRate _PlayRate = PlayRate.Normal;
            private Double _IncrementalValue;
      
            public ChildVideo1()
            {
                InitializeComponent();

                Loaded += new RoutedEventHandler(ChildVideo1_Loaded);
            }

            void ChildVideo1_Loaded(object sender, RoutedEventArgs e)
            {
                CreateNewTimer();
                fastb.MouseLeftButtonDown += new MouseButtonEventHandler(fastb_MouseLeftButtonDown);      
      
            }

            void fastb_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                MyVideo1.Pause();

                if (_PlayTimer == null)
                {
                    CreateNewTimer();

                }

                if (_PlayRate == PlayRate.Normal)
                {
                    _PlayRate = PlayRate.X1FF;
                    _IncrementalValue = 1;
                    _PlayTimer.Start();

                }
                else if (_PlayRate == PlayRate.X1FF)
                {
                    _PlayRate = PlayRate.X2FF;
                    _IncrementalValue = 3;
                    _PlayTimer.Start();
                }
                else
                {
                    MyVideo1.Pause();
                    _PlayRate = PlayRate.Normal;
                    _IncrementalValue = 0;
                    _PlayTimer.Stop();
                    _PlayTimer = null;
                    MyVideo1.Play();
                }
            }

            private void CreateNewTimer()
            {
                _PlayTimer = new DispatcherTimer();
                _PlayTimer.Interval = new TimeSpan(0,0,0,0,500);
                _PlayTimer.Tick += new EventHandler(_PlayTimer_Tick);
            }

            void _PlayTimer_Tick(object sender, EventArgs e)
            {
                double MediaDurationInSeconds = Math.Round(MyVideo1.NaturalDuration.TimeSpan.TotalSeconds);

                double CurPos = MyVideo1.Position.Seconds;
                double AddTime = CurPos = _IncrementalValue;

                double NewPos = Math.Min(MediaDurationInSeconds, Math.Max(0.0,AddTime));

                TimeSpan NewPosition = TimeSpan.FromSeconds(NewPos);
                MyVideo1.Position = NewPosition;
            }

            private void OKButton_Click(object sender, RoutedEventArgs e)
            {
                this.DialogResult = true;
            }

            private void CancelButton_Click(object sender, RoutedEventArgs e)
            {
                this.DialogResult = false;
            }

            private void PlayVid1(object sender, System.Windows.Input.MouseButtonEventArgs e)
            {
                MyVideo1.Play();
            }

            private void PauseVid1(object sender, System.Windows.Input.MouseButtonEventArgs e)
            {
             MyVideo1.Pause();
            }

            private void StopVid1(object sender, System.Windows.Input.MouseButtonEventArgs e)
            {
             MyVideo1.Stop();
            }
        }
    }

     

    Friday, September 3, 2010 11:15 AM