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
Toggling with incremental delay time
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Toggling with incremental delay time
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 ...
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 ...
Re: Toggling with incremental delay time
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.
Kind regards
Bernd
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.
Kind regards
Bernd
Re: Toggling with incremental delay time
Hi Bernd
Thanks very much for that. It does look like the answer to my problem, with a bit of tweaking.
Cheers
Don
Thanks very much for that. It does look like the answer to my problem, with a bit of tweaking.
Cheers
Don