Windows10
VisualStudio 2017 C#
を使用しております。
動画の再生中にGUIの操作を受け付け、動画の停止を行えるように作成をしたいです。
動画の読み込みにはAForge.Video.FFMPEG.VideoFileReaderを使用し、
MPEG形式で作成した動画を読み込みます。
動画の表示は、VideroFileRederのReadVideoFrame関数を使用し
フレーム毎に画像を取りだし、pictureBoxに描画を繰り返すことで表示しています。
現在、動画を再生しているときにGUIが固まってしまい、ボタンなどの操作を受け付けない状態です。
Task等しらべ、delegateなどを追加しましたがボタンの操作を受け付けません。
動画再生中にGUIの操作を受け付ける方法について、参考になるページや、
方法等ございましたら、何かアドバイスをいただけないでしょうか?
C#
1 private void MoviePlayButton_Click(object sender, EventArgs e) 2 { 3 //pictureBox1の表示 4 //再生スピードのwaitをいれる 5 6 pictureBox1.Visible = true; 7 8 OpenFileDialog openFileDialog = new OpenFileDialog(); 9 10 openFileDialog.Filter = "(*.avi)|*.avi"; 11 12 if (moviePath == "") 13 { 14 openFileDialog.InitialDirectory = mainFolderPath; 15 } 16 else 17 { 18 openFileDialog.InitialDirectory = movieFolder; 19 } 20 21 if (openFileDialog.ShowDialog() == DialogResult.OK) 22 { 23 //動画再生 24 Task movietask = Task.Run(() => 25 { 26 Invoke(new delegate1 (ReadMovieProc), openFileDialog.FileName); 27 //ReadMovieProc(openFileDialog.FileName); 28 }); 29 30 //ReadMovieProc(openFileDialog.FileName); 31 } 32 33 } 34 35 //0326 追加 36 delegate void delegate1(string filename); 37 38 private void ReadMovieProc(string fileName) 39 { 40 //VideoReader 41 VideoFileReader videoReader = new VideoFileReader(); 42 Bitmap readImage; 43 try 44 { 45 //frameLate 30fps 46 TimeSpan taskFramelata = TimeSpan.FromMilliseconds(usbCamFramerate); 47 videoReader.Open(fileName); 48 int frameCount = (int)videoReader.FrameCount; 49 for (int i = 0; i < (frameCount - 1); i++) 50 { 51 readImage = videoReader.ReadVideoFrame(); 52 pictureBox1.Image = readImage; 53 Thread.Sleep(taskFramelata); //1000msec->1sec 54 pictureBox1.Refresh(); 55 readImage.Dispose(); 56 } 57 } 58 catch (Exception ex) 59 { 60 MessageBox.Show(ex.ToString(), "Movie read error", MessageBoxButtons.OK, MessageBoxIcon.Error); 61 } 62 if (pictureBox1.Image != null) 63 { 64 pictureBox1.Image = null; 65 } 66 videoReader.Close(); 67 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/27 01:16