Players and Sounds - stuff you might want to know

Graham Samuel livfoss at
Thu Dec 19 10:00:42 EST 2013

Just in case it may be helpful to others, here's a summary of stuff I found out when trying to play MP3 files within a LiveCode standalone on a Mac. Some is documented in the LC docs (like point 3) and some isn't. If anyone feels like correcting or extending it, feel free.

1. The 'play' command won't play MP3s, in fact it won't play any sound files of reasonable size. So you need to set up a player to play the far more compressed MP3 format.

2. When a player starts, a 'playStarted' message is sent to the player's script. Correspondingly, when it stops, a 'playStopped' is sent.

3. When you direct a pre-existing player towards a specific sound file ('set the filename of player "myPlayer" to myPath...), the action of doing this fires off a 'playStopped' handler in the player. So if you were hoping to do something when the player had stopped and had scripted your player accordingly, that script will run prematurely unless you lock messages when you update the filename property of your player.

4. When you start a sound playing with a player, it will continue until it stops naturally (i.e. at the end of the file, unless it loops) **provided** you don't switch cards. If you do, playing immediately stops. If you want to have a sound playing while cards change, then put your player on a card in a substack which is remains open at the card containing the player (the stack doesn't have to be visible).

5. If you adopt the method in (4) above, you must make sure that your substack containing players is actually open at the right card before you start trying to run a player. Just writing into a player in the substack (for example by setting the 'filename' property of a player in it) doesn't open it. If you try to play from an unopened card, the attempt to play will silently fail. If you try the same thing in the IDE, you won't get the failure, presumably because the IDE opens all the substacks in your project without an explicit 'go' from you. Like all "works in the IDE, doesn't work in the standalone" issues, I find it very confusing.

6. Some people set the currentTime of a player to 0 before starting to play, to ensure that play starts from the beginning. As long as your intention is simply to run your sound from beginning to end each time, I don't think this is necessary. It looks like the currentTime is reset to zero automatically when the playing finishes.

7. Others set the playRate of the player to 1, which not only sets the player's speed but also starts it playing! Again, for me this didn't seem to make a difference over simply starting the player.

8. The construct 'wait until the sound is done' doesn't apply to players, only to sounds played directly by the 'play' command. If  you want the equivalent functionality with a player, you have to grow your own by writing a regularly called handler that compares the currentTime of the player with its duration, and simply loops until they coincide.

Doubtless there are zillions of other things I should have learned, but that's all I can report so far.



More information about the Use-livecode mailing list