Finite looping of audio

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
froggy
Posts: 7
Joined: Sun Aug 23, 2020 3:36 pm

Finite looping of audio

Post by froggy » Mon Aug 24, 2020 9:13 pm

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...

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Finite looping of audio

Post by richmond62 » Mon Aug 24, 2020 9:52 pm

Code: Select all

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

froggy
Posts: 7
Joined: Sun Aug 23, 2020 3:36 pm

Re: Finite looping of audio

Post by froggy » Tue Aug 25, 2020 6:12 pm

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.

jiml
Posts: 339
Joined: Sat Dec 09, 2006 1:27 am

Re: Finite looping of audio

Post by jiml » Tue Aug 25, 2020 6:53 pm

You might also try this:

Code: Select all

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

froggy
Posts: 7
Joined: Sun Aug 23, 2020 3:36 pm

Re: Finite looping of audio

Post by froggy » Wed Aug 26, 2020 7:25 pm

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!

jiml
Posts: 339
Joined: Sat Dec 09, 2006 1:27 am

Re: Finite looping of audio

Post by jiml » Thu Aug 27, 2020 7:51 pm

You're welcome.
We are all here to help each other.

Post Reply