Page 1 of 1

2 SetTimer -1 at same time, and SoundPlay, , 1

Posted: 16 Oct 2019, 05:46
by mobadihp
Anyone can help me to make music loop? I was trying like this, but SoundPlay, , 1 make the twinkle label waiting too for it's done

Code: Select all

#SingleInstance, force
#Persistent

Menu, Tray, NoStandard
Menu, Tray, NoIcon
Gui, Font, tBold s120
Gui, Add, Text, +Center vMusic, PLAYING
Gui, Show, , Loop

SetTimer, TwinkleText, -1
SetTimer, MusicLoop, -1
Return

MusicLoop:
SoundPlay, DOFAKIN.mp3, 1
SetTimer, MusicLoop, -1
Return

TwinkleText:
Gui, Font, cRed
GuiControl, Font, Music
Sleep, 1000
Gui, Font, cBlack
GuiControl, Font, Music
Sleep, 1000
SetTimer, TwinkleText, -1
Return

Re: 2 SetTimer -1 at same time, and SoundPlay, , 1

Posted: 16 Oct 2019, 20:17
by gregster
Soundplay is a very simple command and certainly not ideally suited for things like this, but one possible and easy workaround might be to create a timer that calls Soundplay after a certain time, that means, the time that the sound file needs to run once...

Code: Select all

;[...]
SetTimer, TwinkleText, -1
gosub, MusicLoop 
SetTimer, MusicLoop, 10500
Return

MusicLoop:
SoundPlay, DOFAKIN.mp3
Return
; [...]
This code assumes that your mp3 takes 10.5 seconds (10500 milliseconds) to run once - but this won't be necessarily an exact procedure...

For more precise looping, given this setting with the constantly flashing GUI, external software/DLLs might help... or perhaps AHK_H ?!
Putting the soundplay part in a separate script that is controlled by the main script, might be another option.

Re: 2 SetTimer -1 at same time, and SoundPlay, , 1

Posted: 17 Oct 2019, 07:15
by mobadihp
gregster wrote:
16 Oct 2019, 20:17
Soundplay is a very simple command and certainly not ideally suited for things like this, but one possible and easy workaround might be to create a timer that calls Soundplay after a certain time, that means, the time that the sound file needs to run once...

Code: Select all

;[...]
SetTimer, TwinkleText, -1
gosub, MusicLoop 
SetTimer, MusicLoop, 10500
Return

MusicLoop:
SoundPlay, DOFAKIN.mp3
Return
; [...]
This code assumes that your mp3 takes 10.5 seconds (10500 milliseconds) to run once - but this won't be necessarily an exact procedure...

For more precise looping, given this setting with the constantly flashing GUI, external software/DLLs might help... or perhaps AHK_H ?!
Putting the soundplay part in a separate script that is controlled by the main script, might be another option.
Thanks for your help, i'll try another option then.

Re: 2 SetTimer -1 at same time, and SoundPlay, , 1

Posted: 17 Oct 2019, 11:10
by Hellbent
I haven't had to deal with Soundplay many times in the past.

When I had used it, I just put the soundplay in another script and used the first script to run it whenever I wanted it to play/ play again.