Jump to content

Soundplay with Countdown Timer (tooltip)


Recommended Posts

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:

Link to comment
Share on other sites

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

Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...