TheNorwegianUser Posted April 18, 2013 Share Posted April 18, 2013 In this sort of a music player I made, the timer starts before the music starts. Because of that, it also is a couple of seconds left that it doesn't play, because it ends when _soundgetpos and _soundgetlength is equal. I even made it wait 5 seconds before ending the song after they're equal. How can I get it more accurate? Whole code, you probably don't have all the includes, so use the second one. (I think you have most includes that are in the 2nd.) expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=C:\Users\Elias\Documents\Autoit\Laptop\Shutdown\peace.ico #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Sound.au3> #include <INet.au3> #include <GUIConstantsEx.au3> #include <Date.au3>#Include <_FileListToArray.au3> #include <GUICtrlOnHover.au3> #include <_AudioEndpointVolume.au3> If not FileExists(@ScriptDir & "\Songs") Then DirCreate(@ScriptDir & "\Songs") MsgBox(0, "Get Started!", "Move songs into the 'Songs' folder to listen to them before falling asleep!" & @CRLF & @CRLF & "Add at least 5 songs!") EndIf local $Dir="" $FindFolders=_FileListToArray(@ScriptDir & "\Songs","*",2) if not @error then $Dir=FileSelectFolder("Select the folder you want your songs played from. Using the 'Songs' folder will play a random song from every folder!", @ScriptDir & "\Songs") If @error = 1 then Exit EndIf If $Dir = "" Then $Dir = @ScriptDir & "\Songs" Local $last, $2ndlast, $3rdlast, $4thlast, $random, $open, $DisplayTime, $Timeleft, $length, $sFormattedTime, $do, $timer, $MakeToolTip, $ToolTip, $GetNewTimer, $GetNewSoon, $volumetimer $Getnew=1 $Pause=1 $Nosong=0 $firstvolume=True If @HOUR<>23 Then If @MIN>39 Then $time = @HOUR+1 & ":" & @MIN-30 If @MIN>29 And @MIN<40 Then $time = @HOUR+1 & ":0" & @MIN-30 If @MIN<30 Then $time = @Hour & ":" & @MIN+30 If @MIN>39 Then $1 = @HOUR+1 & ":" & @MIN-30 If @MIN>29 And @MIN<40 Then $1 = @HOUR+1 & ":0" & @MIN-30 If @MIN<30 Then $1 = @Hour & ":" & @MIN+30 EndIf If @HOUR=23 Then If @MIN>39 Then $time = @HOUR-23 & "0:" & @MIN-30 If @MIN>29 And @MIN<40 Then $time = @HOUR+1 & ":0" & @MIN-30 If @MIN<30 Then $time = @Hour & ":" & @MIN+30 If @MIN>39 Then $1 = @HOUR-23 & "0:" & @MIN-30 If @MIN>29 And @MIN<40 Then $1 = @HOUR+1 & ":0" & @MIN-30 If @MIN<30 Then $1 = @Hour & ":" & @MIN+30 EndIf $Files=_Filelisttoarrayex($Dir) if @error Then MsgBox(0, "Error:", "Error: Add at least 5 songs in the 'Songs' directory before trying again!") ShellExecute(@ScriptDir & "\Songs") Exit EndIf GUICreate("", 150, 225) $SDType=GUICtrlCreateCombo("Shutdown", 10, 175, 130, 20) GUICtrlSetData($SDType, "Logoff|Reboot|Standby|Hibernate|Exit Program", "Shutdown") _GUICtrl_OnHoverRegister($SDType, "StartSDTypeToolTip", "HideToolTip") $Turnofftime=GUICtrlCreateInput($time, 50, 10, 35, 20) $Apply=GUICtrlCreateButton("Applied", 90, 10, 50, 20) _GUICtrl_OnHoverRegister($Apply, "StartApplyToolTip", "HideToolTip") $Undo=GUICtrlCreateButton("Undo", 10, 10, 35, 20) _GUICtrl_OnHoverRegister($Undo, "StartUndoToolTip", "HideToolTip") $Start=GUICtrlCreateButton("Start", 10, 40, 130, 20) _GUICtrl_OnHoverRegister($Start, "StartStartToolTip", "HideToolTip") $Next=GUICtrlCreateButton("Next Song", 10, 70, 130, 20) _GUICtrl_OnHoverRegister($Next, "StartNextToolTip", "HideToolTip") $Help=GUICtrlCreateButton("?", 10, 100, 130, 20) _GUICtrl_OnHoverRegister($Help, "StartHelpToolTip", "HideToolTip") $DecreaseSound=GUICtrlCreateCheckbox("Decrease Sound?", 10, 128) _GUICtrl_OnHoverRegister($DecreaseSound, "StartDecreaseSoundToolTip", "HideToolTip") $AnyKey=GUICtrlCreateCheckbox("TouchShutdown?", 10, 145) _GUICtrl_OnHoverRegister($AnyKey, "StartAnyKeyToolTip", "HideToolTip") $label=GUICtrlCreateLabel("", 10, 205, 60, 20) $label4=GUICtrlCreateLabel("-", 40, 205, 10, 20) $label2=GUICtrlCreateLabel("", 46, 205, 60, 20) $label3=GUICtrlCreateLabel("", 95, 205, 60, 20) GUICtrlCreateGroup("", 5, 0, 140, 35) GUICtrlCreateGroup("", 5, 30, 140, 65) GUICtrlCreateGroup("", 5, 90, 140, 35) GUICtrlCreateGroup("", 5, 120, 140, 49) GUICtrlCreateGroup("", 5, 164, 140, 36) GUICtrlCreateGroup("", 5, 195, 140, 28) GUISetState() $o1=GUICtrlRead($Turnofftime) $o2=GUICtrlRead($Turnofftime) $o3=GUICtrlRead($Turnofftime) $AllFiles=_Filelisttoarrayex($Dir) WHile 1 If $Pause=1 and $1=@HOUR & ":" & @MIN Then ExitLoop If GUICtrlRead($AnyKey)=1 and _IsAnyKeyPressed() Then ExitLoop CheckStuff() $msg=GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $Undo If GUICtrlRead($Apply)="Apply" Then GUICtrlSetData($Turnofftime, $o2) If GUICtrlRead($Apply)="Applied" Then GUICtrlSetData($Turnofftime, $o3) Case $Next If $Nosong=1 Then $Getnew=1 _SoundClose($open) $4thlast=$3rdlast $3rdlast=$2ndlast $2ndlast=$last $last=$random EndIf Case $Help MsgBox(0, "Help", "This program is made so your computer turns itself off at a given time." & @CRLF & @CRLF & "Add songs in the 'Songs' directory, and the program will play a random one when you've pressed start." & @crlf & "Supported filetypes: .mp3" & @CRLF & "The songs can be separated into folders within the 'Songs' folder." & @crlf & "Add at least 5 songs to each folder!" & @CRLF & @CRLF & "It won't shutdown if you have any unsaved data on your computer!") Case $Apply $1=GUICtrlRead($Turnofftime) $o3=$o2 $o2=$1 GUICtrlSetData($Apply, "Applied") Case $Start If $Pause=1 Then If $Getnew=0 Then _SoundResume($open) EndIf $MakePause=0 GUICtrlSetData($Start, "Pause") EndIf If $Pause=0 Then _SoundPause($open) $MakePause=1 GUICtrlSetData($Start, "Start") EndIf If $MakePause=0 Then $Pause=0 If $MakePause=1 Then $Pause=1 EndSwitch If $1=@HOUR & ":" & @MIN Then $do="Shutdown" If $Pause=0 Then If $GetNewSoon=1 And TimerDiff($GetNewTimer)>5000 Then $Getnew=1 $4thlast=$3rdlast $3rdlast=$2ndlast $2ndlast=$last $last=$random $GetNewSoon=0 EndIf If $Getnew=1 Then If $do="Shutdown" Then ExitLoop $random=Random(1, $AllFiles[0], 1) $FileDir=$AllFiles[$random] $type = stringRight($FileDir, 4) If $type<>".mp3" Then $Nosong=1 Else If $random<>$last and $random<>$2ndlast and $random<>$3rdlast and $random<>$4thlast Then _SoundClose($open) $open=_SoundOpen($FileDir) $length=_SoundLength($open, 2) _SoundPlay($open, 0) $Getnew=0 $Nosong=1 EndIf EndIf EndIf If _SoundPos($open, 2) > $length-1 Then $GetNewTimer=TimerInit() $GetNewSoon=1 EndIf EndIf GetAllTimes() WEnd _SoundClose($open) $SD=GUICtrlRead($SDType) If $SD = "Shutdown" Then $SD = 1 If $SD = "Logoff" Then $SD = 0 If $SD = "Reboot" Then $SD = 2 If $SD = "Standby" Then $SD = 32 If $SD = "Hibernate" Then $SD = 64 If $SD = "Exit Program" Then Exit Shutdown($SD) Func CheckStuff() If GUICtrlRead($DecreaseSound)=1 Then DecreaseVolume() EndIf If TimerDiff($Timer)>1400 and $MakeToolTip=True Then ToolTip($ToolTip) $MakeToolTip=False EndIf If $o1<>GUICtrlRead($Turnofftime) Then $o1=GUICtrlRead($Turnofftime) GUICtrlSetData($Apply, "Apply") EndIf If $o2=GUICtrlRead($Turnofftime) And GUICtrlRead($Apply)="Apply" Then GUICtrlSetData($Apply, "Applied") EndIf EndFunc Func DecreaseVolume() If $Pause=0 Then if $firstvolume=True then $volumetimer=TimerInit() $firstvolume = False EndIf If TimerDiff($volumetimer)>120000 Then $getvolume=_GetMasterVolumeLevelScalar() If $getvolume<1 Then $getvolume=1 _SetMasterVolumeLevelScalar($getvolume-1) $volumetimer=TimerInit() EndIf EndIf EndFunc Func GetAllTimes() $2=@HOUR & ":" & @MIN & ":" & @SEC $11=$1 & ":00" $1TrimLeft=StringTrimLeft($11, 6) $1TrimRight=StringTrimRight($11, 6) $2TrimLeft=StringTrimLeft($2, 6) $2TrimRight=StringTrimRight($2, 6) $1GetMiddle1=StringTrimLeft($11, 3) $1GetMiddle2=StringTrimRight($1GetMiddle1, 3) $2GetMiddle1=StringTrimLeft($2, 3) $2GetMiddle2=StringTrimRight($2GetMiddle1, 3) $1Trim=$1GetMiddle2*60+$1TrimLeft+$1TrimRight*3600 $2Trim=$2GetMiddle2*60+$2TrimLeft+$2TrimRight*3600 $sOldFormattedTime=$sFormattedTime If $1Trim>$2Trim Then $Trim=($1Trim-$2Trim)*1000 $sFormattedTime = _TimeReadable2($Trim) EndIf If $1Trim<$2Trim Then $sEndDT = _DateAdd("D", 1, _NowCalcDate()) & " " & $1 & ":00" $iDiff = _DateDiff("s", _NowCalc(), $sEndDT) $iHours = Int($iDiff / 3600) $iMinutes = Int(($iDiff - ($iHours * 3600)) / 60) $iSeconds = $iDiff - (($iHours * 3600) + ($iMinutes * 60)) $sFormattedTime = StringRight("0" & $iHours, 2) & ":" & StringRight("0" & $iMinutes, 2) & ":" & StringRight("0" & $iSeconds, 2) EndIf If $do="Shutdown" Then $sFormattedTime="00:00:00" If $sOldFormattedTime<>$sFormattedTime Then GUICtrlSetData($label3, $sFormattedTime) $OldDisplayTime=$DisplayTime $OldTimeleft=$Timeleft $DisplayTime = _SoundPos($open, 2) $Timeleft = $length-$DisplayTime $Timeleft = _TimeReadable($Timeleft) $DisplayTime = _TimeReadable($DisplayTime) If $OldDisplayTime <> $DisplayTime Then GUICtrlSetData($label, $DisplayTime) If $OldTimeleft <> $Timeleft Then GUICtrlSetData($label2, $Timeleft) EndFunc Func _IsAnyKeyPressed($vDLL = 'user32.dll') If __KeyPressCheck(1, 221, -1, $vDLL) Then Return 1 Return 0 EndFunc Func __KeyPressCheck($iStart, $iFinish, $iHexKey = -1, $vDLL = 'user32.dll') Local $ikey, $ia_R For $ikey = $iStart To $iFinish If $iHexKey == -1 Then $ia_R = DllCall($vDLL, 'int', 'GetAsyncKeyState', 'int', '0x' & Hex($ikey, 2)) If $iHexKey <> -1 Then $ia_R = DllCall($vDLL, 'int', 'GetAsyncKeyState', 'int', '0x' & $iHexKey) If Not @error And BitAND($ia_R[0], 0x8000) = 0x8000 Then Return 1 Next Return 0 EndFunc Func _TimeReadable($mili) $TotalSeconds = Int($mili / 1000) $Hours = Int($TotalSeconds / 3600) $Minutes = Int(($TotalSeconds - ($Hours * 3600)) / 60) $Seconds = $TotalSeconds - (($Hours * 3600) + ($Minutes * 60)) If $Hours < 10 Then $Hours = "0" & $Hours If $Minutes < 10 Then $Minutes = "0" & $Minutes If $Seconds < 10 Then $Seconds = "0" & $Seconds $FormattedTime = $Minutes & ":" & $Seconds Return $FormattedTime EndFunc Func _TimeReadable2($mili) $TotalSeconds = Int($mili / 1000) $Hours = Int($TotalSeconds / 3600) $Minutes = Int(($TotalSeconds - ($Hours * 3600)) / 60) $Seconds = $TotalSeconds - (($Hours * 3600) + ($Minutes * 60)) If $Hours < 10 Then $Hours = "0" & $Hours If $Minutes < 10 Then $Minutes = "0" & $Minutes If $Seconds < 10 Then $Seconds = "0" & $Seconds $FormattedTime = $Hours & ":" & $Minutes & ":" & $Seconds Return $FormattedTime EndFunc Func StartHelpToolTip() $MakeToolTip=True $timer=TimerInit() $ToolTip="Need Help? Click Here!" EndFunc Func StartNextToolTip() $MakeToolTip=True $timer=TimerInit() $ToolTip="Open the next song" EndFunc Func StartAnyKeyToolTip() $MakeToolTip=True $timer=TimerInit() $ToolTip="Shuts down if any key is pressed" EndFunc Func StartUndoToolTip() $MakeToolTip=True $timer=TimerInit() $ToolTip="Undo current time" EndFunc Func StartStartToolTip() $MakeToolTip=True $timer=TimerInit() If GUICtrlRead($Start)="Start" Then $ToolTip="Start playing songs" If GUICtrlRead($Start)="Pause" Then $ToolTip="Pause current song" EndFunc Func StartSDTypeToolTip() $MakeToolTip=True $timer=TimerInit() $ToolTip="What kind of shutdown?" EndFunc Func StartDecreaseSoundToolTip() $MakeToolTip=True $timer=TimerInit() $ToolTip="Decreases sound one step every 2 minutes" EndFunc Func StartApplyToolTip() $MakeToolTip=True $timer=TimerInit() If GUICtrlRead($Apply)="Applied" Then $ToolTip="Inserted time is alredy applied" If GUICtrlRead($Apply)="Apply" Then $ToolTip="Apply inserted time" EndFunc Func HideToolTip() $MakeToolTip=False ToolTip("") EndFunc expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=C:\Users\Elias\Documents\Autoit\Laptop\Shutdown\peace.ico #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Sound.au3> #include <INet.au3> #include <GUIConstantsEx.au3> #include <Date.au3> ;~ #Include <_FileListToArray.au3> ;~ #include <GUICtrlOnHover.au3> ;~ #include <_AudioEndpointVolume.au3> If not FileExists(@ScriptDir & "\Songs") Then DirCreate(@ScriptDir & "\Songs") MsgBox(0, "Get Started!", "Move songs into the 'Songs' folder to listen to them before falling asleep!" & @CRLF & @CRLF & "Add at least 5 songs!") EndIf local $Dir="" $FindFolders=_FileListToArray(@ScriptDir & "\Songs","*",2) if not @error then $Dir=FileSelectFolder("Select the folder you want your songs played from. Using the 'Songs' folder will play a random song from every folder!", @ScriptDir & "\Songs") If @error = 1 then Exit EndIf If $Dir = "" Then $Dir = @ScriptDir & "\Songs" Local $last, $2ndlast, $3rdlast, $4thlast, $random, $open, $DisplayTime, $Timeleft, $length, $sFormattedTime, $do, $timer, $MakeToolTip, $ToolTip, $GetNewTimer, $GetNewSoon, $volumetimer $Getnew=1 $Pause=1 $Nosong=0 $firstvolume=True If @HOUR<>23 Then If @MIN>39 Then $time = @HOUR+1 & ":" & @MIN-30 If @MIN>29 And @MIN<40 Then $time = @HOUR+1 & ":0" & @MIN-30 If @MIN<30 Then $time = @Hour & ":" & @MIN+30 If @MIN>39 Then $1 = @HOUR+1 & ":" & @MIN-30 If @MIN>29 And @MIN<40 Then $1 = @HOUR+1 & ":0" & @MIN-30 If @MIN<30 Then $1 = @Hour & ":" & @MIN+30 EndIf If @HOUR=23 Then If @MIN>39 Then $time = @HOUR-23 & "0:" & @MIN-30 If @MIN>29 And @MIN<40 Then $time = @HOUR+1 & ":0" & @MIN-30 If @MIN<30 Then $time = @Hour & ":" & @MIN+30 If @MIN>39 Then $1 = @HOUR-23 & "0:" & @MIN-30 If @MIN>29 And @MIN<40 Then $1 = @HOUR+1 & ":0" & @MIN-30 If @MIN<30 Then $1 = @Hour & ":" & @MIN+30 EndIf $Files=_Filelisttoarrayex($Dir) if @error Then MsgBox(0, "Error:", "Error: Add at least 5 songs in the 'Songs' directory before trying again!") ShellExecute(@ScriptDir & "\Songs") Exit EndIf GUICreate("", 150, 225) $SDType=GUICtrlCreateCombo("Shutdown", 10, 175, 130, 20) GUICtrlSetData($SDType, "Logoff|Reboot|Standby|Hibernate|Exit Program", "Shutdown") $Turnofftime=GUICtrlCreateInput($time, 50, 10, 35, 20) $Apply=GUICtrlCreateButton("Applied", 90, 10, 50, 20) $Undo=GUICtrlCreateButton("Undo", 10, 10, 35, 20) $Start=GUICtrlCreateButton("Start", 10, 40, 130, 20) $Next=GUICtrlCreateButton("Next Song", 10, 70, 130, 20) $Help=GUICtrlCreateButton("?", 10, 100, 130, 20) $DecreaseSound=GUICtrlCreateCheckbox("Decrease Sound?", 10, 128) $AnyKey=GUICtrlCreateCheckbox("TouchShutdown?", 10, 145) $label=GUICtrlCreateLabel("", 10, 205, 60, 20) $label4=GUICtrlCreateLabel("-", 40, 205, 10, 20) $label2=GUICtrlCreateLabel("", 46, 205, 60, 20) $label3=GUICtrlCreateLabel("", 95, 205, 60, 20) GUICtrlCreateGroup("", 5, 0, 140, 35) GUICtrlCreateGroup("", 5, 30, 140, 65) GUICtrlCreateGroup("", 5, 90, 140, 35) GUICtrlCreateGroup("", 5, 120, 140, 49) GUICtrlCreateGroup("", 5, 164, 140, 36) GUICtrlCreateGroup("", 5, 195, 140, 28) GUISetState() $o1=GUICtrlRead($Turnofftime) $o2=GUICtrlRead($Turnofftime) $o3=GUICtrlRead($Turnofftime) $AllFiles=_Filelisttoarrayex($Dir) WHile 1 If $Pause=1 and $1=@HOUR & ":" & @MIN Then ExitLoop If GUICtrlRead($AnyKey)=1 and _IsAnyKeyPressed() Then ExitLoop CheckStuff() $msg=GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $Undo If GUICtrlRead($Apply)="Apply" Then GUICtrlSetData($Turnofftime, $o2) If GUICtrlRead($Apply)="Applied" Then GUICtrlSetData($Turnofftime, $o3) Case $Next If $Nosong=1 Then $Getnew=1 _SoundClose($open) $4thlast=$3rdlast $3rdlast=$2ndlast $2ndlast=$last $last=$random EndIf Case $Help MsgBox(0, "Help", "This program is made so your computer turns itself off at a given time." & @CRLF & @CRLF & "Add songs in the 'Songs' directory, and the program will play a random one when you've pressed start." & @crlf & "Supported filetypes: .mp3" & @CRLF & "The songs can be separated into folders within the 'Songs' folder." & @crlf & "Add at least 5 songs to each folder!" & @CRLF & @CRLF & "It won't shutdown if you have any unsaved data on your computer!") Case $Apply $1=GUICtrlRead($Turnofftime) $o3=$o2 $o2=$1 GUICtrlSetData($Apply, "Applied") Case $Start If $Pause=1 Then If $Getnew=0 Then _SoundResume($open) EndIf $MakePause=0 GUICtrlSetData($Start, "Pause") EndIf If $Pause=0 Then _SoundPause($open) $MakePause=1 GUICtrlSetData($Start, "Start") EndIf If $MakePause=0 Then $Pause=0 If $MakePause=1 Then $Pause=1 EndSwitch If $1=@HOUR & ":" & @MIN Then $do="Shutdown" If $Pause=0 Then If $GetNewSoon=1 And TimerDiff($GetNewTimer)>5000 Then $Getnew=1 $4thlast=$3rdlast $3rdlast=$2ndlast $2ndlast=$last $last=$random $GetNewSoon=0 EndIf If $Getnew=1 Then If $do="Shutdown" Then ExitLoop $random=Random(1, $AllFiles[0], 1) $FileDir=$AllFiles[$random] $type = stringRight($FileDir, 4) If $type<>".mp3" Then $Nosong=1 Else If $random<>$last and $random<>$2ndlast and $random<>$3rdlast and $random<>$4thlast Then _SoundClose($open) $open=_SoundOpen($FileDir) $length=_SoundLength($open, 2) _SoundPlay($open, 0) $Getnew=0 $Nosong=1 EndIf EndIf EndIf If _SoundPos($open, 2) > $length-1 Then $GetNewTimer=TimerInit() $GetNewSoon=1 EndIf EndIf GetAllTimes() WEnd _SoundClose($open) $SD=GUICtrlRead($SDType) If $SD = "Shutdown" Then $SD = 1 If $SD = "Logoff" Then $SD = 0 If $SD = "Reboot" Then $SD = 2 If $SD = "Standby" Then $SD = 32 If $SD = "Hibernate" Then $SD = 64 If $SD = "Exit Program" Then Exit Shutdown($SD) Func CheckStuff() If GUICtrlRead($DecreaseSound)=1 Then DecreaseVolume() EndIf If TimerDiff($Timer)>1400 and $MakeToolTip=True Then ToolTip($ToolTip) $MakeToolTip=False EndIf If $o1<>GUICtrlRead($Turnofftime) Then $o1=GUICtrlRead($Turnofftime) GUICtrlSetData($Apply, "Apply") EndIf If $o2=GUICtrlRead($Turnofftime) And GUICtrlRead($Apply)="Apply" Then GUICtrlSetData($Apply, "Applied") EndIf EndFunc Func DecreaseVolume() If $Pause=0 Then ;~ Do stuff you cant do without audioendpointvolume EndIf EndFunc Func GetAllTimes() $2=@HOUR & ":" & @MIN & ":" & @SEC $11=$1 & ":00" $1TrimLeft=StringTrimLeft($11, 6) $1TrimRight=StringTrimRight($11, 6) $2TrimLeft=StringTrimLeft($2, 6) $2TrimRight=StringTrimRight($2, 6) $1GetMiddle1=StringTrimLeft($11, 3) $1GetMiddle2=StringTrimRight($1GetMiddle1, 3) $2GetMiddle1=StringTrimLeft($2, 3) $2GetMiddle2=StringTrimRight($2GetMiddle1, 3) $1Trim=$1GetMiddle2*60+$1TrimLeft+$1TrimRight*3600 $2Trim=$2GetMiddle2*60+$2TrimLeft+$2TrimRight*3600 $sOldFormattedTime=$sFormattedTime If $1Trim>$2Trim Then $Trim=($1Trim-$2Trim)*1000 $sFormattedTime = _TimeReadable2($Trim) EndIf If $1Trim<$2Trim Then $sEndDT = _DateAdd("D", 1, _NowCalcDate()) & " " & $1 & ":00" $iDiff = _DateDiff("s", _NowCalc(), $sEndDT) $iHours = Int($iDiff / 3600) $iMinutes = Int(($iDiff - ($iHours * 3600)) / 60) $iSeconds = $iDiff - (($iHours * 3600) + ($iMinutes * 60)) $sFormattedTime = StringRight("0" & $iHours, 2) & ":" & StringRight("0" & $iMinutes, 2) & ":" & StringRight("0" & $iSeconds, 2) EndIf If $do="Shutdown" Then $sFormattedTime="00:00:00" If $sOldFormattedTime<>$sFormattedTime Then GUICtrlSetData($label3, $sFormattedTime) $OldDisplayTime=$DisplayTime $OldTimeleft=$Timeleft $DisplayTime = _SoundPos($open, 2) $Timeleft = $length-$DisplayTime $Timeleft = _TimeReadable($Timeleft) $DisplayTime = _TimeReadable($DisplayTime) If $OldDisplayTime <> $DisplayTime Then GUICtrlSetData($label, $DisplayTime) If $OldTimeleft <> $Timeleft Then GUICtrlSetData($label2, $Timeleft) EndFunc Func _IsAnyKeyPressed($vDLL = 'user32.dll') If __KeyPressCheck(1, 221, -1, $vDLL) Then Return 1 Return 0 EndFunc Func __KeyPressCheck($iStart, $iFinish, $iHexKey = -1, $vDLL = 'user32.dll') Local $ikey, $ia_R For $ikey = $iStart To $iFinish If $iHexKey == -1 Then $ia_R = DllCall($vDLL, 'int', 'GetAsyncKeyState', 'int', '0x' & Hex($ikey, 2)) If $iHexKey <> -1 Then $ia_R = DllCall($vDLL, 'int', 'GetAsyncKeyState', 'int', '0x' & $iHexKey) If Not @error And BitAND($ia_R[0], 0x8000) = 0x8000 Then Return 1 Next Return 0 EndFunc Func _TimeReadable($mili) $TotalSeconds = Int($mili / 1000) $Hours = Int($TotalSeconds / 3600) $Minutes = Int(($TotalSeconds - ($Hours * 3600)) / 60) $Seconds = $TotalSeconds - (($Hours * 3600) + ($Minutes * 60)) If $Hours < 10 Then $Hours = "0" & $Hours If $Minutes < 10 Then $Minutes = "0" & $Minutes If $Seconds < 10 Then $Seconds = "0" & $Seconds $FormattedTime = $Minutes & ":" & $Seconds Return $FormattedTime EndFunc Func _TimeReadable2($mili) $TotalSeconds = Int($mili / 1000) $Hours = Int($TotalSeconds / 3600) $Minutes = Int(($TotalSeconds - ($Hours * 3600)) / 60) $Seconds = $TotalSeconds - (($Hours * 3600) + ($Minutes * 60)) If $Hours < 10 Then $Hours = "0" & $Hours If $Minutes < 10 Then $Minutes = "0" & $Minutes If $Seconds < 10 Then $Seconds = "0" & $Seconds $FormattedTime = $Hours & ":" & $Minutes & ":" & $Seconds Return $FormattedTime EndFunc Func _FileListToArrayEx($s_path, $s_mask = "*.*", $i_flag = 0, $s_exclude = -1, $f_recurse = True, $f_full_path = True) If FileExists($s_path) = 0 Then Return SetError(1, 1, 0) ; Strip trailing backslash, and add one after to make sure there's only one $s_path = StringRegExpReplace($s_path, "[\\/]+\z", "") & "\" ; Set all defaults If $s_mask = -1 Or $s_mask = Default Then $s_mask = "*.*" If $i_flag = -1 Or $i_flag = Default Then $i_flag = 0 If $s_exclude = -1 Or $s_exclude = Default Then $s_exclude = "" ; Look for bad chars If StringRegExp($s_mask, "[/:><\|]") Or StringRegExp($s_exclude, "[/:><\|]") Then Return SetError(2, 2, 0) EndIf ; Strip leading spaces between semi colon delimiter $s_mask = StringRegExpReplace($s_mask, "\s*;\s*", ";") If $s_exclude Then $s_exclude = StringRegExpReplace($s_exclude, "\s*;\s*", ";") ; Confirm mask has something in it If StringStripWS($s_mask, 8) = "" Then Return SetError(2, 2, 0) If $i_flag < 0 Or $i_flag > 2 Then Return SetError(3, 3, 0) ; Validate and create path + mask params Local $a_split = StringSplit($s_mask, ";"), $s_hold_split = "" For $i = 1 To $a_split[0] If StringStripWS($a_split[$i], 8) = "" Then ContinueLoop If StringRegExp($a_split[$i], "^\..*?\..*?\z") Then $a_split[$i] &= "*" & $a_split[$i] EndIf $s_hold_split &= '"' & $s_path & $a_split[$i] & '" ' Next $s_hold_split = StringTrimRight($s_hold_split, 1) If $s_hold_split = "" Then $s_hold_split = '"' & $s_path & '*.*"' Local $i_pid, $s_stdout, $s_hold_out, $s_dir_file_only = "", $s_recurse = "/s " If $i_flag = 1 Then $s_dir_file_only = ":-d" If $i_flag = 2 Then $s_dir_file_only = ":D" If Not $f_recurse Then $s_recurse = "" $i_pid = Run(@ComSpec & " /c dir /b " & $s_recurse & "/a" & $s_dir_file_only & " " & $s_hold_split, "", @SW_HIDE, 4 + 2) While 1 $s_stdout = StdoutRead($i_pid) If @error Then ExitLoop $s_hold_out &= $s_stdout WEnd $s_hold_out = StringRegExpReplace($s_hold_out, "\v+\z", "") If Not $s_hold_out Then Return SetError(4, 4, 0) ; Parse data and find matches based on flags Local $a_fsplit = StringSplit(StringStripCR($s_hold_out), @LF), $s_hold_ret $s_hold_out = "" If $s_exclude Then $s_exclude = StringReplace(StringReplace($s_exclude, "*", ".*?"), ";", "|") For $i = 1 To $a_fsplit[0] If $s_exclude And StringRegExp(StringRegExpReplace( _ $a_fsplit[$i], "(.*?[\\/]+)*(.*?\z)", "\2"), "(?i)\Q" & $s_exclude & "\E") Then ContinueLoop If StringRegExp($a_fsplit[$i], "^\w:[\\/]+") = 0 Then $a_fsplit[$i] = $s_path & $a_fsplit[$i] If $f_full_path Then $s_hold_ret &= $a_fsplit[$i] & Chr(1) Else $s_hold_ret &= StringRegExpReplace($a_fsplit[$i], "((?:.*?[\\/]+)*)(.*?\z)", "$2") & Chr(1) EndIf Next $s_hold_ret = StringTrimRight($s_hold_ret, 1) If $s_hold_ret = "" Then Return SetError(5, 5, 0) Return StringSplit($s_hold_ret, Chr(1)) EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 18, 2013 Moderators Share Posted April 18, 2013 TheNorwegianUser,Why are you not using the Sound.au3 function that is designed to tell you when a sound file has ended? The return from _SoundStatus will do what you want without the need to measure the elapsed time of the track itself. M23 TheNorwegianUser 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
TheNorwegianUser Posted April 19, 2013 Author Share Posted April 19, 2013 TheNorwegianUser,Why are you not using the Sound.au3 function that is designed to tell you when a sound file has ended? The return from _SoundStatus will do what you want without the need to measure the elapsed time of the track itself. M23Oh, thanks!Also, which filetypes can it play? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 19, 2013 Moderators Share Posted April 19, 2013 TheNorwegianUser, In principle the UDF shoudl work on all sound file types for which you have a CODEC installed and which are accessible by the MCI DLL. I use it very successfully on mp3, wma and wav files - I have not tried on any others as that is all I use. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now