进入Button1_Click事件
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.InitialDirectory = "c:\"
OpenFileDialog1.Filter = "mp3 文件(*.mp3)|*.mp3|CD音频文件(*.wav)|*.wav|" & "视频(*.asf)|*.asf|所有文件(*.*)|*.*"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
AxWindowsMediaPlayer1.URL = OpenFileDialog1.FileName
ListBox1.Items.Add(OpenFileDialog1.FileName)
End If
End Sub
OpenFileDialog1.InitialDirectory = "c:\"
OpenFileDialog1.Filter = "mp3 文件(*.mp3)|*.mp3|CD音频文件(*.wav)|*.wav|" & "视频(*.asf)|*.asf|所有文件(*.*)|*.*"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
AxWindowsMediaPlayer1.URL = OpenFileDialog1.FileName
ListBox1.Items.Add(OpenFileDialog1.FileName)
End If
End Sub
进入Button2_Click事件
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button2.Text = "播放" Then
AxWindowsMediaPlayer1.Ctlcontrols.pause()
Button2.Text = "暂停"
Else
AxWindowsMediaPlayer1.Ctlcontrols.play()
Button2.Text = "播放"
End If
End Sub
If Button2.Text = "播放" Then
AxWindowsMediaPlayer1.Ctlcontrols.pause()
Button2.Text = "暂停"
Else
AxWindowsMediaPlayer1.Ctlcontrols.play()
Button2.Text = "播放"
End If
End Sub
Private Sub 打开ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开ToolStripMenuItem.Click
Button1_Click(sender, e)
End Sub
Button1_Click(sender, e)
End Sub
进入Button3_Click事件
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
AxWindowsMediaPlayer1.Ctlcontrols.stop() '停止
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition() = 0 '重新开始
AxWindowsMediaPlayer1.URL = ""
End Sub
AxWindowsMediaPlayer1.Ctlcontrols.stop() '停止
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition() = 0 '重新开始
AxWindowsMediaPlayer1.URL = ""
End Sub
进入 打开ToolStripMenuItem_Click事件
进入打开目录ToolStripMenuItem_Click事件
Private Sub 打开目录ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开目录ToolStripMenuItem.Click
If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim fi As IO.FileInfo
Dim dir As IO.DirectoryInfo = New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
Dim file As String
For Each fi In dir.GetFiles("*.mp3")
file = fi.FullName
ListBox1.Items.Add(file)
Next
End If
End Sub
Dim fi As IO.FileInfo
Dim dir As IO.DirectoryInfo = New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
Dim file As String
For Each fi In dir.GetFiles("*.mp3")
file = fi.FullName
ListBox1.Items.Add(file)
Next
End If
End Sub
进入关闭ToolStripMenuItem_Click事件
Private Sub 关闭ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 关闭ToolStripMenuItem.Click
''关闭
If MessageBox.Show("请确定你要关闭吗?", "关闭", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then
Close()
Else
Return
End If
End Sub
''关闭
If MessageBox.Show("请确定你要关闭吗?", "关闭", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then
Close()
Else
Return
End If
End Sub
进入Timer1_Tick事件
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
HScrollBar1.Value = AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
End Sub
HScrollBar1.Value = AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
End Sub
进入HScrollBar1_Scroll事件
Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
''进度条
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition() = HScrollBar1.Value
End Sub
''进度条
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition() = HScrollBar1.Value
End Sub
进入ListBox1_DoubleClick事件
Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem.ToString
End Sub
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem.ToString
End Sub
代码已经输入完毕,接下来我们需要运行程序进行测试。
好了程序运行成功,此播放器已经具备了最基本的功能。感兴趣的朋友还可以向程序增加更多的功能。