使用了DirectShowLib-2005.dll控件播放视频的一个样例

经过了本地好几个视频的测试,发现只有播放 mkv 格式的视频没有花屏. 不知道怎么弄还是用回自带的wmp.dll算了

点击项目>添加引用>选择DirectShowLib-2005.dll

以下是代码:

先添加一个按钮

Imports DirectShowLib

Imports System.Runtime.InteropServices

Public Class Form5

Private Sub Button1_Click_1(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("E:\keyfc\Air\动画\[FLsnow][DVDRIP][AIR][Collection]\MAIN MOVIE\[FLsnow][AIR TV][DVDRip][03][XVID+MP3].mkv", Nothing)

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

End Class

你可能感兴趣的:(使用了DirectShowLib-2005.dll控件播放视频的一个样例)