VB 用API 函数如何获取视频音频文件的播放时长
用WindowsMediaPlayer控件虽然能够得到播放时长,但在打开视频文件时常出错导致强制性中断关闭退出,用以下这么API函数如何获得常见视频音频文件的播放时长呢?...
用Windows Media Player 控件虽然能够得到播放时长,但在打开视频文件时常出错导致强制性中断关闭退出,用以下这么API函数如何获得常见视频音频文件的播放时长呢?能有具体的函数用法示例最好了。
Public Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrCommand As String) As Long
Public Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Public Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
Public 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 Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long
Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
不知道以上这些API函数如何调用才能返回文件的播放时长,或者是哪些函数如何使用才能返回播放时长?
调试琢磨后发现一个现象,文件名中带空格的话,就不能正确打开文件,何故? 展开
Public Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrCommand As String) As Long
Public Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Public Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
Public 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 Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long
Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
不知道以上这些API函数如何调用才能返回文件的播放时长,或者是哪些函数如何使用才能返回播放时长?
调试琢磨后发现一个现象,文件名中带空格的话,就不能正确打开文件,何故? 展开
3个回答
展开全部
'获取媒体的长度 00:00
Public Function GetMusicLengthString(FileName As String) As String
Dim RefStr As String * 80
mciSendString "status " & FileName & " length", RefStr, 80, 0
GetMusicLengthString = CStr(Format(Int(Val(RefStr) \ 1000 \ 60), "00") & ":" & Format(Val(RefStr) \ 1000 Mod 60, "00.") & Val(RefStr) \ 100 Mod 10)
End Function
Public Function GetMusicLengthString(FileName As String) As String
Dim RefStr As String * 80
mciSendString "status " & FileName & " length", RefStr, 80, 0
GetMusicLengthString = CStr(Format(Int(Val(RefStr) \ 1000 \ 60), "00") & ":" & Format(Val(RefStr) \ 1000 Mod 60, "00.") & Val(RefStr) \ 100 Mod 10)
End Function
更多追问追答
追问
此函数返回的是空值0.
追答
我调试过,没问题呀。
?GetMusicLengthString("e:\mp3\明天,你好.MP3")
04:29.9
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Public Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
追问
这个函数哪是获取时间差的函数,而是删除文件的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以直接通过每秒字节数换算
参考
参考
更多追问追答
追问
按照那资料上说的,但执行打开命令时,无法成功打开文件,返回值不为0,故也就无法后续操作,不知何故。
OpenSuc = mciSendString("open " + sFile + "type mp3 Alias Music", 0&, 0, 0)
If OpenSuc 0 Then
OpenSuc = mciSendString("open " + sFile + " type MPEGVideo Alias Movies", 0&, 0, 0)
If OpenSuc = 0 Then
..
Else
...
End If
Else
End If
追答
第一个type前面有个空格
参考资料: http://wenku.baidu.com/view/00b4431352d380eb62946dda.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询