Sign in to follow this  
Followers 0
Diana (Cda)

[Resolved.] Tray portion of script doesn't work during SoundPlay

5 posts in this topic

#1 ·  Posted (edited)

I use this snippet in a lot of scripts since the built-in exit script in AutoIt scripts often just has never worked well. When one clicks to exit a script, the exit seems to get confused with the pause and no matter how carefully you click on it, pause is what gets invoked - and it seems to have always been that way. But I long ago started using my own exit snippet scripts I knew could be exited early and that has always worked perfectly well. This is the code (not showing the Quit part that is usually put at the bottom of the script):

;*****===== Tray EXIT button: =====*****=====*****=====*****=====*****=====****
    Opt("GuiOnEventMode", 1)
    Opt("TrayOnEventMode", 1)
    Opt("TrayMenuMode", 1)
    ;------------------------------------------------------------------------------
    TrayCreateItem("")     ; creates a "separator" line between  items in tray menu
    TrayCreateItem("")     ; creates a "separator" line between  items in tray menu
    TrayCreateItem("Exit")
    TrayItemSetOnEvent(-1, "_Quit")
    TrayCreateItem("")     ; creates a "separator" line between  items in tray menu
    TrayCreateItem("")     ; creates a "separator" line between  items in tray menu
    ;*****=====*****=====*****=====*****=====*****=====*****=====****=====****=====

As I said, it works for most scripts. But I've just come across a situation recently where in a certain script, a 5 minute music reminder file is played and it's one I often can shut down when its job of reminding is accomplished if I'm close to the computer. But the exit part above seems to get knocked out the instant the soundplay part of the code hits and the music starts. Kind of really defeats the purpose of having this code in there for this one!!

I tried making the above into a Func _Exit() type of thing and then calling it hoping to bypass soundplay's making this inaccessible but that didn't do the job.

Is there a different way of coding a user-defined exit for scripts, perhaps? Something that _does_ work during a soundplay function?

Thanks!! :)

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites



All I can think about your problem is: SoundPlay is a blocking function so while it is executed, nothing else works.

What you can try is: to define a HotKey and your exit button to send that hotkey.

Add this on top of your script:

HotKeySet("!AX", "ForceExit")

Then put the following code inside your _Quit() function:

Send("!AX")

Then add a new function:

Func ForceExit()
Exit
EndFunc

This is a workaround, I have not tested it so I don't know if it works. Tll somebody else could give you a proper answer, you have nothing to lose by trying this.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

As I said, it works for most scripts. But I've just come across a situation recently where in a certain script, a 5 minute music reminder file is played and it's one I often can shut down when its job of reminding is accomplished if I'm close to the computer. But the exit part above seems to get knocked out the instant the soundplay part of the code hits and the music starts. Kind of really defeats the purpose of having this code in there for this one!!

Using flag 0 on SounPlay function and a Sleep works for me. Maybe this is not what you need but... ;-)

;*****===== Tray EXIT button: =====*****=====*****=====*****=====*****=====****
Opt("GuiOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
;------------------------------------------------------------------------------
TrayCreateItem("")     ; creates a "separator" line between  items in tray menu
TrayCreateItem("")     ; creates a "separator" line between  items in tray menu
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Quit")
TrayCreateItem("")     ; creates a "separator" line between  items in tray menu
TrayCreateItem("")     ; creates a "separator" line between  items in tray menu
;*****=====*****=====*****=====*****=====*****=====*****=====****=====****=====

SoundPlay(@ScriptDir & "\test.mp3",0) ; 0 will continue script while sound is playing (default)
Sleep(300000) ;will sleep 5 minutes (change it according to the length of the song)

Func _Quit()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

All I can think about your problem is: SoundPlay is a blocking function so while it is executed, nothing else works.

What you can try is: to define a HotKey and your exit button to send that hotkey.

Add this on top of your script:

HotKeySet("!AX", "ForceExit")

Then put the following code inside your _Quit() function:

Send("!AX")

Then add a new function:

Func ForceExit()
Exit
EndFunc

This is a workaround, I have not tested it so I don't know if it works. Tll somebody else could give you a proper answer, you have nothing to lose by trying this.

That's interesting. I'll have to give it a try, I think, if I want to keep the "1" flag.

Thanks! :)

Share this post


Link to post
Share on other sites

Using flag 0 on SounPlay function and a Sleep works for me. Maybe this is not what you need but... ;-)

[snip]

SoundPlay(@ScriptDir & "\test.mp3",0) ; 0 will continue script while sound is playing (default)

Sleep(300000) ;will sleep 5 minutes (change it according to the length of the song)

Func _Quit()

Exit

EndFunc[/autoit]

So _that's_ what caused it! I changed the flag from 0 to 1 recently, since I found this feature only in last few weeks. But I never connected the fact that the Quit stopped working after that because I don't always cancel this script early. But you're right. For weeks I'd never had any problem closing the script when it had the "0" flag.

So now I have a choice. Flawless exit or flawless song duration via flag 1. I'm guessing the easy exit wins! <g>

Thanks. I've gone back to previous code with flag 0 and added back in the sleep. If only there was a song "fade" function ... <g>

:)

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