Still stuck on playing a sound with a player

J. Landman Gay jacque at hyperactivesw.com
Mon Dec 16 17:26:17 EST 2013


On 12/16/13 2:35 PM, Graham Samuel wrote:
>
> RR Support told me to create a handler that keeps calling itself until
> the currentTime of the player corresponds to its duration - this is
> because my script carries on after the player starts and eventually
> switches cards.

That's not how I do it. When the player reaches the end, it will receive 
a playStopped message which you can trap. That way you don't need to 
keep checking on its progress. The message is sent to the player object 
itself, not to the card it's on, though you could put a handler anywhere 
in the hierarchy. I have this in a player script:

on playStopped
  doPlayStoppedStuff
end playStopped

And then you can put a "doPlayStoppedStuff" handler in the card or stack 
to actually do whatever needs doing when the playback is done. This may 
mean you need to break up your big handler into two separate pieces, but 
this method is cleaner.

A second alternative is to set some callbacks on the player (see 
"callbacks" in the dictionary.) That will allow you to send messages at 
any defined point during playback, and you can have a handler that 
responds to those messages. If you only need to know when the playback 
is finished, just set a single callback at the end.

To prevent the player from stopping during card changes, I put the 
player in a separate substack which isn't visible. It just sits there 
and plays stuff while the main stack is operating. I don't know if that 
will work for you. In my case I don't need a controller so it doesn't 
matter if the player isn't visible. Mine just does background audio, and 
the user turns it on/off with a button on the main card.

Mp3 files work fine for me. If you are getting a duration of zero it 
means the file wouldn't load. What happens if you use the player's 
property inspector to select the file from disk instead of setting it 
with a script? Does it play then? If so, then it's probably a glitch 
somewhere while constructing the file path.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the Use-livecode mailing list