VB6获取音频时长,获取的不准确怎么回事?
VB6用API 函数获取视频音频文件的播放时长 程序代码:
Option Explicit 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 Public Function GetMusicLengthString(FileName As String) As String Dim RefStr As String * 80 mciSendString "status " & FileName & " length", RefStr, 80, 0 GetMusicLengthString = RefStr End Function Private Sub Form_Load() MsgBox GetMusicLengthString("E:\1.mp3") End Sub
程序代码:
Option Explicit 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 Form_Load() Dim r As String r = String(256, Chr(0)) Dim f As String f = "E:\1.mp3" '文件名根据自己需要改 mciSendString "Status " & f & " length", r, 256, 0 Dim m As Long m = Val(r) \ 1000 \ 60 Dim c As Double c = Val(r) / 1000 - m * 60 MsgBox "长度" & m & "分" & c & "秒" End Sub