示例#1
0
        private void replayerSlider_DragCompleted_1(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
        {
            int value = (int)(this.replayerSlider.Value * 1000);

            ReplaySDK.PlayM4_SetPlayedTimeEx(_port, (uint)value);
            timer.Start();
        }
示例#2
0
        private void btnPlayClick(object sender, RoutedEventArgs e)
        {
            try
            {
                if (isPlaying)
                {
                    ReplaySDK.PlayM4_Pause(_port, !(bool)btnPlayPause.IsChecked);
                    if ((bool)btnPlayPause.IsChecked)
                    {
                        timer.Start();
                    }
                    else
                    {
                        timer.Stop();
                    }
                }
                else
                {
                    if (!(bool)checkBoxPlayLocalFile.IsChecked)
                    {
                        var viewModel = DataContext as DataReplayerViewModel;
                        if (viewModel != null && viewModel.SelectedVideo != null)
                        {
                            string directory = string.Format(@"c:\{0}", viewModel.SelectedVideo.Directory);
                            if (!Directory.Exists(directory))
                            {
                                Directory.CreateDirectory(directory);
                            }
                            string file = string.Format(@"c:\{0}", viewModel.SelectedVideo.FullPath);

                            if (!File.Exists(file))
                            {
                                DownloadAndPlayVideoFile(viewModel.SelectedVideo.Address, file);
                            }
                            else
                            {
                                PlayVideoFile(file);
                            }
                        }
                    }
                    else
                    {
                        if (File.Exists(selectedVideoFile))
                        {
                            PlayVideoFile(selectedVideoFile);
                        }
                        else
                        {
                            MessageBox.Show(string.Format("指定的文件不存:{0}", selectedVideoFile));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#3
0
 void VideoReplayerView_Unloaded(object sender, RoutedEventArgs e)
 {
     if (isPlaying)
     {
         btnPlayPause.IsChecked = false;
         ReplaySDK.PlayM4_Pause(_port, !(bool)btnPlayPause.IsChecked);
         timer.Stop();
     }
 }
示例#4
0
 private void btnStopClick(object sender, RoutedEventArgs e)
 {
     isPlaying = false;
     btnPlayPause.IsChecked = false;
     ReplaySDK.PlayM4_Stop(_port);
     ReplaySDK.PlayM4_CloseFile(_port);
     ReplaySDK.PlayM4_FreePort(_port);
     replayerSlider.Value = 0;
     this.pbReplay.Image  = null;
     TBTotalTime.Text     = TimeSpan.FromSeconds(0).ToString();
     TBpassedTime.Text    = TimeSpan.FromSeconds(0).ToString();
 }
示例#5
0
        void timer_Tick(object sender, EventArgs e)
        {
            var time = (double)ReplaySDK.PlayM4_GetPlayedTime(_port);

            TBpassedTime.Text    = TimeSpan.FromSeconds(time).ToString();
            replayerSlider.Value = time;

            position = ReplaySDK.PlayM4_GetPlayPos(_port);
            if (position == 1)
            {
                isPlaying = false;
                btnPlayPause.IsChecked = false;
                timer.Stop();

                ReplaySDK.PlayM4_Stop(_port);
                ReplaySDK.PlayM4_CloseFile(_port);
                ReplaySDK.PlayM4_FreePort(_port);
                this.pbReplay.Image  = null;
                replayerSlider.Value = 0;
                TBTotalTime.Text     = TimeSpan.FromSeconds(0).ToString();
                TBpassedTime.Text    = TimeSpan.FromSeconds(0).ToString();

                if (!(bool)checkBoxPlayLocalFile.IsChecked)
                {
                    var viewModel = DataContext as DataReplayerViewModel;
                    if (viewModel != null)
                    {
                        if (viewModel.MoveToNextVideo())
                        {
                            btnPlayPause.IsChecked = true;
                            //viewModel.SelectedVideo != null
                            string directory = string.Format(@"c:\{0}", viewModel.SelectedVideo.Directory);
                            if (!Directory.Exists(directory))
                            {
                                Directory.CreateDirectory(directory);
                            }
                            string file = string.Format(@"c:\{0}", viewModel.SelectedVideo.FullPath);

                            if (!File.Exists(file))
                            {
                                DownloadAndPlayVideoFile(viewModel.SelectedVideo.Address, file);
                            }
                            else
                            {
                                PlayVideoFile(file);
                            }
                        }
                    }
                }
            }
        }
示例#6
0
        private void PlayVideoFile(string file)
        {
            if (ReplaySDK.PlayM4_GetPort(ref _port))
            {
                ReplaySDK.PlayM4_OpenFile(_port, file);
                double totalseconds = (double)ReplaySDK.PlayM4_GetFileTime(_port);
                this.replayerSlider.Maximum = totalseconds;

                TBTotalTime.Text = TimeSpan.FromSeconds(totalseconds).ToString();
                isPlaying        = ReplaySDK.PlayM4_Play(_port, this.pbReplay.Handle);

                timer.Start();
            }
        }
示例#7
0
 private void btnSlowClick(object sender, RoutedEventArgs e)
 {
     try
     {
         ReplaySDK.PlayM4_Slow(_port);
         double s = double.Parse(this.txbReplaySpeed.Text);
         if (s >= (1f / 8f))
         {
             this.txbReplaySpeed.Text = (s / 2).ToString();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
示例#8
0
 private void btnFastClick(object sender, RoutedEventArgs e)
 {
     try
     {
         ReplaySDK.PlayM4_Fast(_port);
         float s = float.Parse(this.txbReplaySpeed.Text);
         if (s <= 8)
         {
             this.txbReplaySpeed.Text = (s * 2).ToString();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
示例#9
0
 private void btnSnaphotClick(object sender, RoutedEventArgs e)
 {
     try
     {
         byte[] buffer = new byte[this.pbReplay.Width * this.pbReplay.Height * 3 / 2];
         uint   size   = 0;
         if (ReplaySDK.PlayM4_GetJPEG(_port, buffer, (uint)buffer.Length, ref size))
         {
             SnapshotView snapshotView = new SnapshotView();
             snapshotView.SetImageStream(buffer);
             // snapshotView.ImageBox.Source = ByteArrayToBitmapImage(buffer);
             Window window = CreateWindowHostingUserControl(snapshotView);
             window.Width  = 800;
             window.Height = 600;
             window.Show();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
示例#10
0
        private void DownloadAndPlayVideoFile(Uri address, string file)
        {
            WebClient wc = new WebClient();

            wc.DownloadDataCompleted += delegate(object client, DownloadDataCompletedEventArgs we)
            {
                FileStream fileStream = new System.IO.FileStream(file, FileMode.Create, FileAccess.Write);
                // Writes a block of bytes to this stream using data from a byte array.
                fileStream.Write(we.Result, 0, we.Result.Length);
                // close file stream
                fileStream.Close();
                if (ReplaySDK.PlayM4_GetPort(ref _port))
                {
                    ReplaySDK.PlayM4_OpenFile(_port, file);
                    double totalseconds = (double)ReplaySDK.PlayM4_GetFileTime(_port);
                    this.replayerSlider.Maximum = totalseconds;
                    TBTotalTime.Text            = TimeSpan.FromSeconds(totalseconds).ToString();
                    isPlaying = ReplaySDK.PlayM4_Play(_port, this.pbReplay.Handle);

                    timer.Start();
                }
            };
            wc.DownloadDataAsync(address);
        }