调用WindowsMediaPlayer控件播放多个文件【VB .NET】
Private Sub 选择文件ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 选择文件ToolStripMenuItem.Click
'设置打开文件对话框的属性
With Me.OpenFileDialog1.Title = "Open Sound File" '对话框标题
.Filter = "mp3文件(*.mp3)|*.mp3|avi文件|*.avi|全部(*.*)|*.*" '文件过滤
.Multiselect = True '允许多选文件
End With
'打开文件选择对话窗口选择取消时则不执行
If OpenFileDialog1.ShowDialog() = DialogResult.Cancel Then
Exit Sub
End If
For Each filename As String In OpenFileDialog1.FileNames
'将选择文件一个一个加入播放器播放列表
AxWindowsMediaPlayer1.currentPlaylist.appendItem(AxWindowsMediaPlayer1.newMedia(filename))
'将选择文件一个一个加入ListBox1列表
Me.ListBox1.Items.Add(filename)
Next
'开始播放
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub
'双击ListBox播放选中的文件
Private Sub ListBox1_DoubleClick(sender As Object, e As EventArgs) Handles ListBox1.DoubleClick
Dim index As Integer = ListBox1.SelectedIndex
AxWindowsMediaPlayer1.Ctlcontrols.currentItem = AxWindowsMediaPlayer1.currentPlaylist.Item(index)
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub