Sign in to follow this  
Followers 0
Nagato

Soundplay with Countdown Timer (tooltip)

7 posts in this topic

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!. :mellow:

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

you need to memorize the soundplay and tooltip state like this Posted Image

$_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 by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Ok tnx for the code i understand now :)

but the timer got frozen ... :mellow:

Share this post


Link to post
Share on other sites

Ok tnx for the code i understand now :)

but the timer got frozen ... :mellow:

You want just play sound 15 sec and close it or just exitlloop ?


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Thats what im looking for thanks !!

I just added exitloop after the time limit reach...

i will add some more functions for practicing :mellow:

Share this post


Link to post
Share on other sites

Glad to help you !

You must set time left, because mine is time elapsed ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0