'以下代码须要4个Command一个Timer
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub Command1_Click() '播放音乐
mciSendString "close all", 0&, 0, 0 '确保能播放正常,先关闭内存中的音乐
mciSendString "open """ & "c:\春暖花开.mp3" & """ alias OpenFile type MPEGVideo", 0&, 0, 0 '指定音乐文件
mciSendString "play OpenFile", 0&, 0, 0 '播放一次
'mciSendString "play OpenFile From 0 to 9000", 0&, 0, 0 '播放某个部份(从0到9000)
'mciSendString "play OpenFile repeat", 0&, 0, 0 '循环播放
End Sub
Private Sub Command2_Click() '关闭音乐
mciSendString "close OpenFile", 0&, 0, 0
End Sub
Private Sub Command3_Click() '暂停音乐
mciSendString "pause OpenFile", 0&, 0, 0
End Sub
Private Sub Command4_Click() '恢复播放
mciSendString "resume OpenFile", 0&, 0, 0
End Sub
Private Sub Timer1_Timer()
Dim ST1 As String * 64
mciSendString "status OpenFile mode", ST1, Len(ST1), 0
If ST1 = "" Then
Text2 = "准备就绪"
End If
If Left(ST1, 7) = "playing" Then
Text2 = "播放中"
End If
If Left(ST1, 7) = "stopped" Then
Text2 = "播放完毕"
End If
If Left(ST1, 6) = "paused" Then
Text2 = "暂停中"
End If
'----------------------------取播放状态
Dim ST2 As String * 64
mciSendString "status OpenFile length", ST2, Len(ST2), 0
Text1 = Val(ST2)
'----------------------------取播放总时长
Dim ST3 As String * 64
mciSendString "status OpenFile position", ST3, Len(ST3), 0
Text3 = Val(ST3)
'----------------------------取当前播放时间
End Sub