试写了一个,看下是否是这么回事。
注册消息,拦截滑动条消息。 把_play函数中的Canon.mp3换成你的歌曲。
#include <Date.au3>
#include <sound.au3>
Global const $wm_Hscroll = 0x0114
Opt("GuiOnEventMode", 1)
Global $Flag = 0
Local $OldProgress
$hGui = GuiCreate('player', 400, 110)
GuiSetOnEvent(-3, "_exit", $hGui)
$slider = GuiCtrlCreateSlider(20, 20, 360, 20)
GuiCtrlSetOnEvent(-1, "_slider")
$btnPlay = GuiCtrlCreateButton("Play", 60, 60, 60, 30)
GuiCtrlSetOnEvent(-1, "_play")
$btnStop = GuiCtrlCreateButton("Stop", 280, 60, 60, 30)
GuiCtrlSetOnEvent(-1, "_stop")
GuiSetState()
GuiRegisterMsg($wm_Hscroll, "_wmHscroll")
While 1
If $Flag then
sleep(100)
If _soundPos("myMusic", 2) / _soundLength("myMusic", 2) * 100 = $OldProgress then ContinueLoop
GuiCtrlSetData($slider, _soundPos("myMusic", 2) / _soundLength("myMusic", 2) * 100)
$OldProgress = _soundPos("myMusic", 2) / _soundLength("myMusic", 2) * 100
If _soundPos("myMusic") = _soundLength("myMusic") then
_play()
GuiCtrlSetData($slider, 0)
EndIf
ContinueLoop
EndIf
Sleep(2000)
WEnd ;==>main
Func _exit()
exit(0)
EndFunc ;==>_exit()
Func _wmHscroll($hWnd, $message, $wParam, $sParam)
#forceref $hWnd, $message, $wParam, $sParam
Local $hour, $min, $sec
$curPos = GuiCtrlRead($slider) / 100 * _soundLength("mymusic", 2)
_ticksToTime($curPos, $hour, $min, $sec)
$Prompt = stringFormat("%i:%02i:%02i", $hour, $min, $sec)
toolTip($Prompt)
_soundSeek("myMusic", $hour, $min, $sec)
EndFunc ;==>_wmHscroll()
Func _slider()
toolTip('')
If $Flag then _soundPlay("myMusic")
EndFunc ;==>_slider()
Func _play()
If not $Flag then
If _soundPos("myMusic") = _soundLength("myMusic") then
_soundClose("myMusic")
_soundOpen("Canon.Mp3", "myMusic")
EndIf
_soundPlay("myMusic")
GuiCtrlSetData($btnPlay, "Pause")
Else
_soundPause("myMusic")
GuiCtrlSetData($btnPlay, "Play")
EndIf
$Flag = not $Flag
EndFunc ;==>_stop()
Func _stop()
_soundStop("myMusic")
GuiCtrlSetData($btnPlay, "Play")
GuiCtrlSetData($slider, 0)
$Flag = 0
EndFunc ;==>_stop()
|