'Public Declare Function
Private Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrCommand As String) As Long
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 Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Function shortname(LongPath As String) As String
Dim ShortPath As String
Dim pos As String
Dim Ret&
Const MAX_PATH = 260
ShortPath = Space$(MAX_PATH)
Ret& = GetShortPathName(LongPath, ShortPath, MAX_PATH)
If Ret& Then
pos = InStr(1, ShortPath, " ")
shortname = Left$(ShortPath, pos - 2)
End If
End Function
'
Public Sub play(FileName As String)
Dim Cb As Long
Dim PlayStatus As String * 20
Dim ShortFileName As String
Dim TotalLength As Long
If Dir(FileName) = "" Then
MsgBox "文件" & FileName & "不存在!", vbInformation, "提示"
Exit Sub
End If
mciExecute "close all"
ShortFileName = shortname(FileName)
mciExecute "open " & ShortFileName & " alias mp3"
'得到时间长度
mciSendString "status mp3 length", PlayStatus, Len(PlayStatus), Cb
TotalLength = Val(Left(PlayStatus, 9))
End Sub