AGermanUser
Joined: 12 Feb 2005 Posts: 82
|
Posted: Tue Dec 26, 2006 6:35 am Post subject: function GetMP3Len |
|
|
A user in the german forum asked for a way to determine the length of an MP3 file. I pointed him to winmm.dll. Thalon was so kind to finish it up.
I thought it might be good to share the solution, just in case someone is interested. I took Thalons code and created a function from it.
| Code: |
GetMP3Len(In_PathFile)
{
; In_PathFile: Absolute path to your mp3 file - e.g. C:\Music\test.mp3
; Set variable capacities for dllcalls
VarSetCapacity(ShortName, 255)
VarSetCapacity(Length , 255)
; Transforms FilePath into it's 8.3-Value
RetValue := DllCall("kernel32.dll\GetShortPathNameA"
, "Str", In_PathFile
, "Str", ShortName
, "UInt", 255)
; Open MP3
RetValue := DllCall("winmm.dll\mciSendStringA"
, "Str", "open " . ShortName . " type MPEGVideo alias mp3audio"
, "Str", 0
, "UInt", 0
, "UInt", 0)
; Read Length
RetValue := DllCall("winmm.dll\mciSendStringA"
, "Str", "status mp3audio length"
, "Str", Length
, "UInt", 255
, "UInt", 0)
; Close MP3
RetValue := DllCall("winmm.dll\mciSendStringA"
, "Str", "close mp3audio"
, "Str", 0
, "UInt", 0
, "UInt", 0)
; Trim milliseconds -> just seconds needed
StringTrimRight, Length, Length, 3
; Convert the specified number of seconds to hh:mm:ss format.
time = 19990101 ; *Midnight* of an arbitrary date.
time += %Length%, seconds
FormatTime, mmss, %time%, mm:ss
Return mmss ; This method is used to support more than 24 hours worth of sections.
} |
You can use it in your scripts e.g. in a File Loop:
| Code: | Loop, C:\MyMP3s\*.mp3
{
MP3Len := GetMP3Len(A_LoopFileFullPath)
MsgBox, Title:`t%A_LoopFileFullPath%`nLength:`t%MP3Len%
}
... |
_________________ Cheers
BBCodeWriter • ToDo-List • CopyPassage |
|