/// <summary> /// 開くダイアログでOKが押された。ファイルを開いて再生する。 /// </summary> private void openMediaFileDialog_FileOk(object sender, CancelEventArgs e) { // 前に再生していたものを閉じる CloseMedia(); // ファイル名 string path = System.IO.Path.GetFullPath(openMediaFileDialog.FileName); try { // 読み込む graph = new SampleGrabberGraph(path); //graph.RegisterToROT = true; // trueにするとgraphedit.exeから見えるようになる。 graph.Load(); } catch { // error... graph.Dispose(); graph = null; MessageBox.Show("Error occured."); return; } // メディアと同じ形式でオーディオデバイスを開く if (graph.HasAudio) { waveOut = new WinMM.WaveIO.WaveOut(WinMM.WaveIO.WaveOut.WaveMapper, graph.AudioSamplePerSec, graph.AudioBitsPerSample, graph.AudioChannels); graph.AudioFrame += graph_AudioFrame; } // メディアと同じサイズでビデオバッファを作る if (graph.HasVideo) { this.ClientSize = graph.VideoSize; videoBuffer = new Bitmap(graph.VideoSize.Width, graph.VideoSize.Height, PixelFormat.Format32bppArgb); graph.VideoFrame += graph_VideoFrame; } // 再生。 if (graph != null) { graph.Play(); } }
/// <summary> /// キーが押された。各種操作。 /// </summary> private void ExampleMoviePlayer_KeyDown(object sender, KeyEventArgs e) { int seek = 0; switch (e.KeyCode) { case Keys.Enter: openMediaFileDialog.ShowDialog(); break; // 開く case Keys.Space: if (graph != null && !graph.IsPlaying) { graph.Play(); } else if (graph != null) { graph.Pause(); } break; // 再生/一時停止 case Keys.Escape: if (graph != null) { graph.Stop(); } break; // 停止 case Keys.Left: seek = -5000; break; // -5秒 case Keys.Right: seek = +5000; break; // +5秒 } if (seek != 0) { if (graph != null) { graph.CurrentPosition = Math.Max(0, graph.CurrentPosition + seek); } if (waveOut != null) { waveOut.Stop(); } } }
/// <summary> /// 開くダイアログでOKが押された。ファイルを開いて再生する。 /// </summary> private void openMediaFileDialog_FileOk(object sender, CancelEventArgs e) { // 前に再生していたものを閉じる CloseMedia(); // ファイル名 string path = System.IO.Path.GetFullPath(openMediaFileDialog.FileName); try { // 読み込む graph = new SampleGrabberGraph(path); //graph.RegisterToROT = true; // trueにするとgraphedit.exeから見えるようになる。 graph.Load(); } catch { // error... graph.Dispose(); graph = null; MessageBox.Show("Error occured."); return; } // メディアと同じ形式でオーディオデバイスを開く if (graph.HasAudio) { waveOut = new WinMM.WaveIO.WaveOut(WinMM.WaveIO.WaveOut.WaveMapper, graph.AudioSamplePerSec, graph.AudioBitsPerSample, graph.AudioChannels); graph.AudioFrame += graph_AudioFrame; } // メディアと同じサイズでビデオバッファを作る if (graph.HasVideo) { this.ClientSize = graph.VideoSize; videoBuffer = new Bitmap(graph.VideoSize.Width, graph.VideoSize.Height, PixelFormat.Format32bppArgb); graph.VideoFrame += graph_VideoFrame; } // 再生。 if (graph != null) graph.Play(); }