#include <Sound.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
Opt('MustDeclareVars', 1)
Global $hSound, $iTime, $sFilePlay = @ScriptDir & '\file.mp3', _
$nLabel_All, $nLabel_Time, $iStart, $nProgress, $iStartUpdate
GUICreate('Test', 300, 120)
$nLabel_All = GUICtrlCreateLabel('', 10, 10, 100, 20)
$nLabel_Time = GUICtrlCreateLabel('', 10, 40, 280, 20)
$nProgress = GUICtrlCreateProgress(10, 80, 280, 20)
GUISetState()
$hSound = _SoundOpen($sFilePlay)
If @error Then _Exit()
$iTime = _SoundLength($hSound, 2)
If @error Then _Exit()
GUICtrlSetData($nLabel_All, StringFormat('All time %.1f sec', $iTime / 1000))
_Play()
AdlibRegister('_Play', $iTime)
AdlibRegister('_Time', 500)
ToolTip(StringFormat('%02d:%02d:%02d', @HOUR, @MIN, @SEC), 0, 0)
$iStartUpdate = TimerInit()
While 1
If TimerDiff($iStartUpdate) >= 1000 Then
ToolTip(StringFormat('%02d:%02d:%02d', @HOUR, @MIN, @SEC), 0, 0)
$iStartUpdate = TimerInit()
EndIf
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
_Exit()
EndSwitch
WEnd
Func _Play()
GUICtrlSetData($nProgress, 0)
$iStart = TimerInit()
_SoundPlay($hSound, 0)
EndFunc ;==>_Play
Func _Time()
Local $i_Timer = TimerDiff($iStart), $i_Persent = 100 * $i_Timer / $iTime
If $i_Persent > 100 Then $i_Persent = 100
GUICtrlSetData($nProgress, Int($i_Persent))
GUICtrlSetData($nLabel_Time, StringFormat('Time play: %.1f sec, time left: %.1f sec, play: %.1f%', _
$i_Timer / 1000, ($iTime - $i_Timer) / 1000, $i_Persent))
EndFunc ;==>_Time
Func _Exit()
_SoundClose($hSound)
Exit
EndFunc ;==>_Exit