干货源码
Imports System.IO
Imports System.Security.Cryptography
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Button1.Text = “上一曲”
Button4.Text = “播放”
Button3.Text = “下一曲”
Button2.Text = “顺序播放”
Button7.Text = “打开文件”
Button6.Text = “打开目录”
Button9.Text = “本地视频”
Button8.Text = “网络视频”
Button5.Text = “搜索歌曲”
Label1.Text = “00:00”
Label2.Text = “00:00”
Label3.Text = “歌词显示”
Label4.Text = “未播放”
Label5.Text = “正在播放:”
Label6.Text = “20%”
End Sub
Dim files(), paths()
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
OpenFileDialog1.Filter = “选择音频|.mp3;.flac;.wav;.mp4”
OpenFileDialog1.Multiselect = True
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
localSelectPathList.Clear()
ListBox1.Items.Clear()
If files Is Nothing Then
Else
Array.Clear(files)
End If
If paths Is Nothing Then
Else
Array.Clear(paths)
End If
files = OpenFileDialog1.FileNames
paths = OpenFileDialog1.FileNames
For Each file In files
ListBox1.Items.Add(file)
Next file
End If
End Sub
Dim localSelectPath As String
Dim localSelectPathList As New List(Of String)
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
localSelectPath = FolderBrowserDialog1.SelectedPath
For Each path In Directory.GetFiles(localSelectPath)
localSelectPathList.Add(path)
ListBox1.Items.Add(path)
Next path
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If localSelectPathList.Count > 0 Then
AxWindowsMediaPlayer1.URL = localSelectPathList.Item(ListBox1.SelectedIndex)
AxWindowsMediaPlayer1.Ctlcontrols.play()
Else
AxWindowsMediaPlayer1.URL = paths.GetValue(ListBox1.SelectedIndex)
AxWindowsMediaPlayer1.Ctlcontrols.play()
End If
Button4.Text = "暂停"
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If Button4.Text Is "暂停" Then
Button4.Text = "播放"
AxWindowsMediaPlayer1.Ctlcontrols.pause()
Else
Button4.Text = "暂停"
AxWindowsMediaPlayer1.Ctlcontrols.play()
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If ListBox1.Items Is Nothing Then
Return
End If
If ListBox1.SelectedIndex = 0 Then
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
Else
ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If ListBox1.Items Is Nothing Then
Return
End If
If ListBox1.SelectedIndex = ListBox1.Items.Count - 1 Then
ListBox1.SelectedIndex = 0
Else
ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
End If
End Sub
End Class
图形界面设计
运行后效果截图
功能总结
项目已经实现程序相关功能,本项目中播放器通过导入微软自带控件实现。判断写法略麻烦,不如C#,java等面向对象语言语法清晰简洁。