Toggling with incremental delay time

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
grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Toggling with incremental delay time

Post by grovecat » Thu Nov 24, 2011 10:08 am

This one is a little tricky to describe (and beyond my capabilities to resolve).

My app has buttons, each of which plays a song file (loaded via iTunes document share). Pressing a button causes the relevant song to play, and pressing the same button again pauses the playback, and so on. This part all works OK, but the requirement is to be able to set a time (say 60 seconds) for the song to play before it stops. The user may play/pause the song a few times, and it should stop when the total time of all the playing segments reaches the set time.

You may wonder why on earth anyone would want to do this. It's an app to be used by my occupational therapist son to evaluate the performance of low-functioning disabled children.

Anyway, I can't see how to implement the requirement, so help would be appreciated as usual -- hint hint, Klaus.

Cheers
Don

grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Re: Toggling with incremental delay time

Post by grovecat » Thu Nov 24, 2011 11:07 am

Looks like I may be able to use the seconds function for this.

Initialise a variable tAccumulated to zero at the first press of a button.
Put the seconds into a variable tStart
When the button toggles to Pause, put the seconds into a variable tEnd
Subtract tStart from tEnd and add that to a variable tAccumulated
Compare tAccumulated to the desired total play time and act accordingly.
When the button toggles to Play, put the seconds into tStart
When the button toggles to Pause, put the seconds into a variable tEnd
Compare tAccumulated to the desired total play time and act accordingly.

I think that may do it ...

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Toggling with incremental delay time

Post by bn » Thu Nov 24, 2011 9:56 pm

Hi Grovecat,

if I understood correctly what you want then this may help you.

I made a stack that consists of a player object and one button. Assign a file to the player in the properties inspector.

Than click the Start button. When you click the Start button and it is not in a "playing" cycle it triggers a send in time message that will stop and reset the player in 60 seconds. In the meantime you can start and stop the player as often as you want. When the time is up the the "cleanUp" handler will reset the whole thing. The advantage of "send in time" is that in the meantime you can easily do other things by script or let the user interact without tying Livecode up in a script that runs and pauses.

The trick is to make a script local variable (a variable declared at the top of a script that will be persistent for that script) which keeps track of the status of the "playing" cycle.

All logic is in the button.
startStopPlayer60Seconds.livecode.zip
(1.27 KiB) Downloaded 221 times
Kind regards

Bernd

grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Re: Toggling with incremental delay time

Post by grovecat » Fri Nov 25, 2011 1:57 pm

Hi Bernd

Thanks very much for that. It does look like the answer to my problem, with a bit of tweaking.

Cheers
Don

Post Reply