Need a message that a player is finished

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
AlexAdams
Posts: 38
Joined: Sat Jan 17, 2009 8:49 pm
Location: Santa Cruz, CA
Contact:

Need a message that a player is finished

Post by AlexAdams » Fri Oct 09, 2009 1:57 am

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,
Alex Adams
(a)2 Technology Parnters
alex@a2technology.com
www.a2technology.com
www.promisstudio.com
831-726-8013

Klaus
Posts: 13878
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Fri Oct 09, 2009 8:45 am

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

AlexAdams
Posts: 38
Joined: Sat Jan 17, 2009 8:49 pm
Location: Santa Cruz, CA
Contact:

Thanks Klaus -- and one more question...

Post by AlexAdams » Fri Oct 09, 2009 5:01 pm

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,
Alex Adams
(a)2 Technology Parnters
alex@a2technology.com
www.a2technology.com
www.promisstudio.com
831-726-8013

Klaus
Posts: 13878
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Wed Oct 14, 2009 2:00 pm

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

DougN
Posts: 20
Joined: Wed Mar 04, 2009 4:09 am

Re: Need a message that a player is finished

Post by DougN » Fri Feb 12, 2010 9:01 pm

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

Klaus
Posts: 13878
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Need a message that a player is finished

Post by Klaus » Fri Feb 12, 2010 9:29 pm

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 :D

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

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Re: Need a message that a player is finished

Post by BvG » Sat Feb 13, 2010 1:40 pm

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.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

DougN
Posts: 20
Joined: Wed Mar 04, 2009 4:09 am

Re: Need a message that a player is finished

Post by DougN » Sun Feb 14, 2010 4:10 am

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.

Post Reply

Return to “Multimedia”