SetBatchLines -1
#SingleInstance Force
Loop
ToolTip % "线程占用测试:" n := n="" ? 1 : ++n
Return
; 由于调用是系统API播放,会对MP3文件规格有所限制。wav标准就不存在这种问题
F1::
缓存上次路径 := 音频文件路径
FileSelectFile, 音频文件路径, , ,选择音频文件, 文件(*.wav; *.mp3)
if 音频文件路径=
Return
停止播放(缓存上次路径)
异步播放音频(音频文件路径)
Return
F2::暂停播放(音频文件路径)
F3::继续播放(音频文件路径)
F4::
音频文件长度 := GetAudioDuration(音频文件路径)
MsgBox % 音频长度时间换算(音频文件长度)
Return
异步播放音频(mFile) {
if !(DN := GetAudioDuration(mFile))
MsgBox 0x10, 不支持此音频文件, 系统API不支持此音频播放,`n可转换成恒定码率再试一次。, 2
DllCall("Winmm\mciSendString", "Str", "Open """ mFile """", "Uint", 0, "Uint", 0, "Uint", 0)
, DllCall("Winmm\mciSendString", "Str", "Play """ mFile """ FROM 000 to " DN, "Uint", 0, "Uint", 0, "Uint", 0)
}
继续播放(mFile) {
DllCall("Winmm\mciSendString", "Str", "Play """ mFile """", "Uint", 0, "Uint", 0, "Uint", 0)
}
暂停播放(mFile) {
DllCall("Winmm\mciSendString", "Str", "Pause """ mFile """", "Uint", 0, "Uint", 0, "Uint", 0)
}
停止播放(mFile) {
DllCall("Winmm\mciSendString", "Str", "Close """ mFile """", "Uint", 0, "Uint", 0, "Uint", 0)
}
; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=40538
音频长度时间换算(DN) {
DURATION_IN_SECONDS := Floor(DN / 1000)
((DURATION_IN_SECONDS >= 3600) ? (HOURS := Floor(DURATION_IN_SECONDS / 3600)) : (HOURS := 00))
((DURATION_IN_SECONDS - (HOURS * 3600) > 0) ? (MINUTES := Floor((DURATION_IN_SECONDS - (HOURS * 3600)) / 60)) : (MINUTES := 00))
MINUTES := SubStr(00 . MINUTES, -1, 2)
((DURATION_IN_SECONDS - (HOURS * 3600) - (MINUTES * 60) > 0) ? (SECONDS := Floor(DURATION_IN_SECONDS - (HOURS * 3600) - (MINUTES * 60))) : (SECONDS := 00))
SECONDS := SubStr(00 . SECONDS, -1, 2)
Return HOURS . ":" . MINUTES . ":" . SECONDS
}
; 获取音频文件长度 By SKAN https://www.autohotkey.com/forum/viewtopic.php?p=361791#361791
GetAudioDuration(mFile) {
VarSetCapacity(DN, 16), DLLFunc := "winmm.dll\mciSendString" (A_IsUnicode ? "W" : "A")
, DllCall(DLLFunc, "Str", "Open """ mFile """ Alias MP3", "Uint", 0, "Uint", 0, "Uint", 0)
, DllCall(DLLFunc, "Str", "Status MP3 Length", "Str", DN, "Uint", 16, "Uint", 0)
, DllCall(DLLFunc, "Str", "Close MP3", "Uint", 0, "Uint", 0, "Uint",0)
Return DN
}
; https://docs.microsoft.com/zh-CN/previous-versions//dd743680(v=vs.85)
/*
; 指定4播放内存文件, 指定1异步播放
FileRead, memWav, *c C:\Windows\Media\Windows Ding.wav
DllCall("Winmm\PlaySound", "ptr", &memWav, "ptr", 0, "uint", 4 | 1)
Sleep, 1500
DllCall("Winmm\PlaySound", "ptr", &memWav, "ptr", 0, "uint", 4 | 1)
Sleep, 1500
*/
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
就服你!大佬