Page 1 of 1
Need a message that a player is finished
Posted: Fri Oct 09, 2009 1:57 am
by AlexAdams
I am building an audio (and then a video) player into an app. I need the play/pause button to change back to play when the audio or video is at the end. Does the player send a message that it has reached the end?
Thanks,
Posted: Fri Oct 09, 2009 8:45 am
by Klaus
Hi Alex,
there is the "playstopped" message, but this will also get fired when the user stops the player.
But when using the "playstopped" message you could always check if the currenttime of the player = the duration of the player, so you know if the player has reached the end.
Know what I mean?
Best
Klaus
Thanks Klaus -- and one more question...
Posted: Fri Oct 09, 2009 5:01 pm
by AlexAdams
Klaus,
Thanks. I see that there is a playstarted and playpaused too. That's perfect.
On a related subject, do you know how I can track the progress of the play? I want to show progress as time passing or time remaining. This seems to need a constant feed of information from the player.
Thanks again,
Posted: Wed Oct 14, 2009 2:00 pm
by Klaus
Hi Alex,
check "currenttime" and "timescale" and "duration" in the docs (Rec Dictionary).
These are props of a player that you can query and do the necessary math
Best
Klaus
Re: Need a message that a player is finished
Posted: Fri Feb 12, 2010 9:01 pm
by DougN
This may be related to what I'm trying to do, so I'm posting here as a continuation of this thread.
I'm using Player objects to play audio on a card. The player is hidden, and play is started with a button on the card. I don't want the user to be able to click on other buttons until the Player has finished.
If I were using an audio file inside the stack, I'd use "wait until the sound is done" to hold things up. Is there a corresponding way to work with a Player object?
I tried this code:
Code: Select all
on mouseUp
start player "9-1"
wait until the playstopped of player "9-1" is true
end mouseUp
but it caused the stack to hang... I never got control back and had to abort the script.
Thanks,
Doug
Re: Need a message that a player is finished
Posted: Fri Feb 12, 2010 9:29 pm
by Klaus
Hi Doug,
"plasstopped" is a message and not a property!
In your script the engine presumes "the playstopped" is a custom property of the player and waits until this property = true, which never happens.
And since "wait" is blocking so you are erm... licked
As you might have read in this thread you could check
...
if the currenttime of player xyz = the duration of player xyz then
## Sound is finished!
...
Best
Klaus
Re: Need a message that a player is finished
Posted: Sat Feb 13, 2010 1:40 pm
by BvG
I think it's rude to block the user when a sound is playing.
The problem with wait is that it cancels every message too. See the following non working example (will block your ide, but you can use ctrl-. (peripod) to cancel):
Code: Select all
on playStarted
set the finished of me to false
wait until the finished of me = true
end playStarted
on playStopped --never happens
set the finished of me to true
end playStopped
Because of that fact, you might consider blocking clicks by overlaying a see trough object (using blending), for example a rectangle graphic. Watch out for keyboard stuff too.
Re: Need a message that a player is finished
Posted: Sun Feb 14, 2010 4:10 am
by DougN
Klaus, thanks for the tip. Here's what I implemented, which works for me:
Code: Select all
start player "9-1"
wait until (the currenttime of player "9-1" = the duration of player "9-1") is true
And BvG, thanks for your interface comment about it being rude to block the user. I added a visual indicator by disabling the other two buttons on the screen while the audio is playing.