flynch 0 Posted October 11, 2007 #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 16 Posted October 11, 2007 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 0 Posted October 11, 2007 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
DW1 102 Posted October 11, 2007 so add a hotkey to exit AutoIt3 Online Help Share this post Link to post Share on other sites
flynch 0 Posted October 11, 2007 [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 1 Posted October 11, 2007 #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
weaponx 16 Posted October 11, 2007 #include <GUIConstants.au3> GUICreate("Hello World", 200, 100) GUICtrlCreateLabel("Music", 60, 8) GUISetState(@SW_SHOW) SoundPlay("D:\Music\Song.mp3",1) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Then ExitLoop EndSwitch WEnd Share this post Link to post Share on other sites
flynch 0 Posted October 11, 2007 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 1 Posted October 11, 2007 I really don't get what you want... Share this post Link to post Share on other sites
DW1 102 Posted October 11, 2007 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? AutoIt3 Online Help Share this post Link to post Share on other sites
DW1 102 Posted October 11, 2007 #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 WEnd ;all your other code goes here Like that? AutoIt3 Online Help Share this post Link to post Share on other sites
Nahuel 1 Posted October 11, 2007 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
DW1 102 Posted October 11, 2007 yeah... I don't get what he wants AutoIt3 Online Help Share this post Link to post Share on other sites
flynch 0 Posted October 11, 2007 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 1 Posted October 11, 2007 (edited) 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 October 11, 2007 by Nahuel Share this post Link to post Share on other sites
flynch 0 Posted October 11, 2007 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