如何用API函数获得MP3、WMA等歌曲的时间长度?

东方之珠 2007-09-06 10:16:23
如何用API函数获得MP3、WMA等歌曲的时间长度?
...全文
539 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
CCfan999 2010-06-08
  • 打赏
  • 举报
回复
用mciSendString这个函数可以获取一些歌曲的信息:
歌曲长度:
TCHAR cmd[266],shortname[256],name[256]="c:\\song\\青花瓷.mp3";
TCHAR buffer[256]; //定义缓冲区的大小
long length,curposition; //length歌曲长度 curposition记录当前播放位置
GetShortPathName(name,shortname,sizeof(shortname)/sizeof(TCHAR)); //转换成短路径

wsprintf(cmd,"status %s length",shortname);
mciSendString(cmd,buffer,sizeof(buffer)/sizeof(TCHAR),NULL);
length=atol(buffer); //单位毫秒

wsprintf(cmd,"status %s positon",shortname);
mciSendString(cmd,buffer,sizeof(buffer)/sizeof(TCHAR),NULL);
curpositon=atol(buffer); //单位毫秒

还有很多 请到:http://www.ahscyz.net.cn/xkzy/ShowArticle.asp?ArticleID=240
daisy8675 2007-09-06
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/5656/5656292.xml?temp=.5834467

看这个帖

ygxcxy 2007-09-06
  • 打赏
  • 举报
回复
TotalLength单位为微秒
ygxcxy 2007-09-06
  • 打赏
  • 举报
回复
play "C:\ABC.mp3" ,也可
ygxcxy 2007-09-06
  • 打赏
  • 举报
回复
Option Explicit

'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

Private Sub Form_Load()
play "C:\ABC.wav"
End Sub

809

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧