Page 1 of 1

Finite looping of audio

Posted: Mon Aug 24, 2020 9:13 pm
by froggy
I have a timer functionality, and once the timer runs out I inform the user by displaying a popup and playing a sound. I found the convenient parameter "looping" to have the sound continue until the user have acknowledged the popup.

Code: Select all

play audioClip "Beep[dot]wav" looping
answer "Timer ended!" with "OK"
play stop
But is there any neat way to not have the sound loop for ever? I still want the popup to remain on the screen, just to kill the sound after some 20-30 loops or something. Compare to the wakeup alarm going of at the neighbours while they are on vacation, and it just keeps beeping the entire summer...

Re: Finite looping of audio

Posted: Mon Aug 24, 2020 9:52 pm
by richmond62

Code: Select all

put 1 into KOUNT
repeat until KOUNT > 30
play audioClip "Beep[dot]wav"
add 1 to KOUNT
end repeat

Re: Finite looping of audio

Posted: Tue Aug 25, 2020 6:12 pm
by froggy
Thanks richmond62, but I'm not quite following where I incorporate my "answer" statement in that loop. If you look at the code in my first post it's not just sound, I also have a popup displayed while the sound is looping, and when the popup is acknowledged by user it also ends the sound. This functionality I want to remain, I just want the sound to end after a while, only leaving the popup active.

Re: Finite looping of audio

Posted: Tue Aug 25, 2020 6:53 pm
by jiml
You might also try this:

Code: Select all

send "play stop" to this card in 3 seconds 
Jim Lambert

Re: Finite looping of audio

Posted: Wed Aug 26, 2020 7:25 pm
by froggy
Thanks jiml, I think I'll go with that solution!

If I'm nitty picking it may not end the sound after a complete loop, so sound may appear to be abruptly cut of. But since we already established the user isn't around to hear it so... And it is a really neat fix, only a single line of code, really like that! Thanks!

Re: Finite looping of audio

Posted: Thu Aug 27, 2020 7:51 pm
by jiml
You're welcome.
We are all here to help each other.