Still stuck on playing a sound with a player

Graham Samuel livfoss at mac.com
Mon Dec 16 17:50:50 EST 2013


Jacque, thanks for the wisdom - with your help, I believe I will get it working. Just picking up one point in your mail, I **do** use the player's property inspector to select the file from disk once and for all - since in my case each of the two players plays just one file, it's the simplest way. But somehow the duration of one of the two files is zero, even though they were both created (as MP3s) by the same app (Fission) by conversion from existing AIFF files, and they've both been attached to their respective players in exactly the same way, and both the original files can be played outside LC without problems. So it's a mystery. Of course it's probably something I've done, but I ain't seen it yet.

I like your idea of a dedicated substack for the players - I can do that easily.

That recommendation from RR support (Neil Roger) was not so good, eh? I think he was trying to help me with the issue of my script running off the end of the card, so to speak. In my original design, this will happen before the recording reaches its natural end, unless I do something to block the script from continuing, hence his idea. With the separate substack idea, I can organise it differently, so I won't need to do the blocking. The displayed card will just sit there until the 'playStopped' handler runs, and that's how we will get to the next card - in my doPlayedStoppedStuff bit.

This just leaves the issue of the zero duration, or duff link or whatever it is. I shall tinker.

I'll tell you what happens.

Thanks again

Graham

BTW, this tiny app I'm building is a dress rehearsal for something much bigger - but if I can't reliably play MP3s (and later on, videos) the real project will be dead.

On 16 Dec 2013, at 23:26, J. Landman Gay wrote:

> 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