Jump to content
Sign in to follow this  
flynch

Staying open

Recommended Posts

flynch

#include <GUIConstants.au3>

GUICreate("Hello World", 200, 100)

GUICtrlCreateLabel("Music", 60, 8)

GUISetState(@SW_SHOW)

SoundPlay("D:\Music\Song.mp3",0)

Sleep(100000)

This is my first script. Been reading the tuts so you'll recognise it. How do I keep the script open during the song? Without having some obsurd Sleep?

Share this post


Link to post
Share on other sites
weaponx

The flag on the SoundPlay() function should be holding your script up until the sound finishes, maybe jsut put a:

While 1

WEnd

at the end of your script.

Share this post


Link to post
Share on other sites
flynch

I knew that, but it stops you from closing the program. So you have to listen to the whole sound. The song is about 5mins and if I want to cancel it then... Ctrl+alt+del ftl.

Share this post


Link to post
Share on other sites
flynch

[optional] This flag determines if the script should wait for the sound to finish before continuing:

1 = wait until sound has finished

0 = continue script while sound is playing (default)

If 1 is there, nothing else in the script will happen because its paused.

If 0 is there, I have to put in a crazy sleep time to stop it quitting 10 seconds into the song.

Share this post


Link to post
Share on other sites
Nahuel

#include <Sound.au3>
$Sound="path to sound"
$Length=_SoundLength($Sound,2)
_SoundPlay($Sound,0)
Sleep($Length)

:)

Share this post


Link to post
Share on other sites
flynch

Nahuels worked =]. But im still not happy with using Sleep.. Weaponx yours did what i said it would do. Played song, then froze. Throughout the song. Had to ctrl+alt+del again -.-.

Share this post


Link to post
Share on other sites
Nahuel

I really don't get what you want...

Share this post


Link to post
Share on other sites
DW1

that is a good question... what DO you want?

Both of the codes posted should work fine

You want to play a song in the background? and then have the script exit after its done playing?

Share this post


Link to post
Share on other sites
Nahuel

You want to play a song in the background? and then have the script exit after its done playing?

Well the one I posted does that. And you can quit by right-clicking the tray icon.... So I don't know.. :)

Share this post


Link to post
Share on other sites
flynch

When I use the one with (the fish avatar forgot his name) it works fine. But doesn't the sleep thing screw up any other code I want to work? Such as after i play the song, I want to click buttons in the program. Won't it stop me from doing ti until the sleep is finished?

Basic outline:

Open program:

Music plays:

Do stuff in program:

Close whenever you want:

Share this post


Link to post
Share on other sites
Nahuel

When I use the one with (the fish avatar forgot his name) it works fine. But doesn't the sleep thing screw up any other code I want to work? Such as after i play the song, I want to click buttons in the program. Won't it stop me from doing ti until the sleep is finished?

Use this then.. should do what you want.

#include <Sound.au3>
$Sound = "path to sound"
$Length = _SoundLength($Sound, 2)
_SoundPlay($Sound, 0)
$timer = TimerInit
While 1
    Sleep(10)
    If TimerDiff($timer) > $Length Then ExitLoop
        ;Do all your stuff here
WEnd
-edit-

wait.. if you want to do something else after, not while playing the song... then there's no problem using sleep() :)

Edited by Nahuel

Share this post


Link to post
Share on other sites
flynch

No I wanted to do it WHILE. I'll try that script. But i can't atm so thanks for the help :)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.