Imports System.Text.RegularExpressions '正则表达式
Public Class 音频播放器
Private 文件路径 As String
Private Sub 音频播放器_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.AllowDrop = True '支持文件拖拽
End Sub
Private Sub 音频播放器_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
Try
If e.Data.GetDataPresent(DataFormats.FileDrop) = True Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub 音频播放器_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
Try
Dim filepaht As String() = e.Data.GetData(DataFormats.FileDrop)
For Each File As String In filepaht
文件路径 = File
'播放音乐文件
Dim 文件名 As String = 文件路径.Substring(文件路径.LastIndexOf("\") + 1)
If InStr(1, 文件路径, ".wav", 1) Or InStr(1, 文件路径, ".mp3", 1) Then
AxWindowsMediaPlayer1.URL = 文件路径
AxWindowsMediaPlayer1.settings.playCount = 2
TextBox1.Text = "系统获取到了音乐文件,开始播放音乐:" & 文件路径
Else
TextBox1.Text = "系统获取到了该文件或文件夹 """ & 文件名 & """,但不是MP3文件,无法播放!"
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class