接着定义一些变量: Dim videoClip As Video = Nothing '注意它们的类型 Dim audioClip As Audio = Nothing
然后在Form_Load里面添加如下代码: Private Sub Form1_Load(...) Handles MyBase.Load Dim dlgOpen As New OpenFileDialog '打开媒体文件 dlgOpen.Filter = "Video Files|*.avi; *.mpg; *.mpeg; *.wmv|" & _ "Audio files|*.wav; *.mp3; *.aiff; *.wma|"
If dlgOpen.ShowDialog = DialogResult.OK Then VB.net基础:简单的DirectX播放器 OpenMedia(dlgOpen.FileName) End If End Sub
然后我们写OpenMedia函数: Private Sub OpenMedia(ByVal FileName As String) Try videoClip = New Video(FileName) '注意Video类的构造函数 videoClip.Owner = me '这里表示视频呈现在窗体上。注意videoClip.Owner的类型 ClientSize = videoClip.DefaultSize '将窗体大小改为视频的大小 videoClip.Play() '开始播放 Catch ex As Exception Try audioClip = New Audio(FileName) '注意Audio类的构造函数 audioClip.Play() Catch ex1 As Exception End Try End Try End Sub