16,554
社区成员
发帖
与我相关
我的任务
分享
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hr As Integer
Dim ev As EventCode
Dim fg As FilterGraph
Dim ifg2 As IFilterGraph2
Dim imc As IMediaControl
Dim ime As IMediaEvent
' Get a filtergraph object
fg = New FilterGraph
ifg2 = DirectCast(fg, IFilterGraph2)
' Get the IMediaControl interface from the fg object
imc = DirectCast(fg, IMediaControl)
' Get the IMediaEvent interface from the fg object
ime = DirectCast(fg, IMediaEvent)
' Build the graph
hr = ifg2.RenderFile("c:\1.avi", Nothing)
DsError.ThrowExceptionForHR(hr)
'---------------------------------------------------------------------------------------
Dim videoWindow As Ivideowindow=ctype(ifg2,Ivideowindow)
'hWin.Handle 你想要设置的播放窗体的HANDLE值,可以是一个PANEL的.
hr = videoWindow.put_Owner( hWin.Handle )
DsError.ThrowExceptionForHR( hr )
hr = videoWindow.put_WindowStyle( WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings )
DsError.ThrowExceptionForHR( hr )
'OABool这个数据类型是包括在那个DLL文件里的
hr = videoWindow.put_Visible( OABool.True )
DsError.ThrowExceptionForHR( hr )
'hwin他就是一个FORM或PANEL,你可以改成FORM1.ClientRectangle,这个FORM就是你的播放窗体,和上面的那个HWIN是一个
Dim rc AS Rectangle = hWin.ClientRectangle
hr = videoWindow.SetWindowPosition( 0, 0, rc.Right, rc.Bottom )
DsError.ThrowExceptionForHR( hr )
'---------------------------------------------------------------------------------------
' Run the graph
hr = imc.Run()
DsError.ThrowExceptionForHR(hr)
' Wait for the entire file to finish playing
hr = ime.WaitForCompletion(-1, ev)
DsError.ThrowExceptionForHR(hr)
' Release the graph (and all its interfaces)
Marshal.ReleaseComObject(fg)
End Sub
IVideoWindow videoWindow = m_FilterGraph as IVideoWindow;
hr = videoWindow.put_Owner( hWin.Handle );
DsError.ThrowExceptionForHR( hr );
hr = videoWindow.put_WindowStyle( WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings );
DsError.ThrowExceptionForHR( hr );
hr = videoWindow.put_Visible( OABool.True );
DsError.ThrowExceptionForHR( hr );
Rectangle rc = hWin.ClientRectangle;
hr = videoWindow.SetWindowPosition( 0, 0, rc.Right, rc.Bottom );
DsError.ThrowExceptionForHR( hr );