VB.NET – DirectShowで動画再生
ちょっとした動画プレーヤーでも自作してみようと思って調査。
難しそうだなと思いましたが、
DirectShowの.NET用ライブラリが公開されており、これを使うことで超簡単に動画再生できました。
下記サイトから最新版をダウンロード
DirectShowNet library
解凍したフォルダにある「DirectShowLib-2005.dll」を参照の追加する。
例:フォームのパネルに動画を表示再生
Imports DirectShowLib
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hr As Integer
Dim filepath As String
Dim fg As FilterGraph
Dim graphBuilder As IGraphBuilder
Dim mediaControl As IMediaControl
Dim videoWindow As IVideoWindow
fg = New FilterGraph
graphBuilder = DirectCast(fg, IGraphBuilder)
mediaControl = DirectCast(fg, IMediaControl)
videoWindow = DirectCast(fg, IVideoWindow)
filepath = “C:\xxx.mpg”
hr = graphBuilder.RenderFile(filepath, Nothing)
’パネルに表示する
videoWindow.put_WindowStyle(WindowStyle.Child)
videoWindow.SetWindowPosition(0, 0, Me.Panel1.Width, Me.Panel1.Height)
videoWindow.put_Owner(Me.Panel1.Handle)
’再生
mediaControl.Run()
End Sub
End Class
コマ送りや、早送りなんかも簡単にできるので
オリジナル動画プレーヤーが簡単に作れますね!
メモ:DirectShow リファレンス
MSDN – IGraphBuilder インターフェイス