Nagato Posted August 4, 2011 Share Posted August 4, 2011 Hello, Im a newbie in autoit so if can someone correct my code Code: _song() Func _song() $min = 0 $sec = 15 ; length of music (not really precise) $taimer = TimerInit() $msg = MsgBox(4, "Play?", "Do you want to play a song?" & @CRLF & "Title: name of music") If $msg = 7 Then Exit While True Sleep(10) SoundPlay("C:\name.mp3", 0) ; <-- 1 with sound but no display ( i want both ) ToolTip("Now Playing: name.mp3 || Time left: " & $min & ":" & $sec & @CRLF & "Artist: (ignore this)" & @CRLF & "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=",50 ,100 ,"Song", 0, 1) If TimerDiff($taimer) > 1000 Then $taimer = TimerInit() $sec -= 1 If $sec = 0 Then $sec = 60 $min -= 1 Switch $min Case 0 $min = 0 EndSwitch EndIf EndIf WEnd EndFunc Problem: On "Soundplay" if i change the wait parameter to 0 the tooltip displays but no sound, if 1 its the opposite... (i want both) I really don't know how to correct it .. and if someone can make a code that can end the script if the timer goes to 0:00 Thanks!. Link to comment Share on other sites More sharing options...
wakillon Posted August 4, 2011 Share Posted August 4, 2011 (edited) you need to memorize the soundplay and tooltip state like this $_ToolTip=0 $_SoundPlay = 0 _song() Func _song() $min = 0 $sec = 15 ; length of music (not really precise) $taimer = TimerInit() $msg = MsgBox(4, "Play?", "Do you want to play a song?" & @CRLF & "Title: name of music") If $msg = 7 Then Exit While True Sleep(10) If Not $_SoundPlay Then $_SoundPlay=SoundPlay("C:\name.mp3", 0) ; 0 = continue script while sound is playing EndIf If Not $_ToolTip Then $_ToolTip = ToolTip("Now Playing: name.mp3 || Time left: " & $min & ":" & $sec & @CRLF & "Artist: (ignore this)" & @CRLF & "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=",50 ,100 ,"Song", 0, 1) EndIf If TimerDiff($taimer) > 1000 Then $taimer = TimerInit() $sec -= 1 If $sec = 0 Then $sec = 60 $min -= 1 Switch $min Case 0 $min = 0 EndSwitch EndIf EndIf WEnd EndFunc Edited August 4, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Nagato Posted August 4, 2011 Author Share Posted August 4, 2011 Ok tnx for the code i understand now but the timer got frozen ... Link to comment Share on other sites More sharing options...
wakillon Posted August 4, 2011 Share Posted August 4, 2011 Ok tnx for the code i understand now but the timer got frozen ... You want just play sound 15 sec and close it or just exitlloop ? AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
wakillon Posted August 4, 2011 Share Posted August 4, 2011 like that ? $_ToolTip=0 $_SoundPlay = 0 $min = 0 $_PlayLimit = 15 ; length of music (not really precise) $taimer = TimerInit() _song() Func _song() $msg = MsgBox(4, "Play?", "Do you want to play a song?" & @CRLF & "Title: name of music") If $msg = 7 Then Exit While True Sleep(10) If Not $_SoundPlay Then $_SoundPlay=SoundPlay("C:\name.mp3", 0) $_SoundTimer = TimerInit() EndIf $_TimerDiff2 = TimerDiff ( $_SoundTimer ) If TimerDiff ( $taimer ) > 1000 Then $min = Int ( $_TimerDiff2 / ( 60 * 1000 ) ) $sec = Int ( ( $_TimerDiff2 - $min * 60 * 1000 ) / 1000 ) $taimer = TimerInit() ToolTip("Now Playing: name.mp3 || Time left: " & StringFormat ( "%02u" & ":" & "%02u", $min, $sec ) & @CRLF & "Artist: (ignore this)" & @CRLF & "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=",50 ,100 ,"Song", 0, 1) EndIf ConsoleWrite ( "$_TimerDiff2 : " & $_TimerDiff2 & @Crlf ) If $_TimerDiff2 > ( $_PlayLimit+1)*1000 Then SoundPlay ( '' ) $_SoundPlay=0 EndIf WEnd Sleep ( 10 ) EndFunc AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Nagato Posted August 4, 2011 Author Share Posted August 4, 2011 Thats what im looking for thanks !! I just added exitloop after the time limit reach... i will add some more functions for practicing Link to comment Share on other sites More sharing options...
wakillon Posted August 4, 2011 Share Posted August 4, 2011 Glad to help you !You must set time left, because mine is time elapsed ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts 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