LiveCode allows you to play sound and video within your application using the player object. The player object described in this lesson is only supported on desktop, for Mobile players please see the lesson How do I play a video in part of the screen on mobile.
Adding a Player Object
The first thing to do is to add a player object to your stack. Do this by dragging it across from the Tools Palette.
Setting the Filename of the Player
You set the filename property of the player object to tell it which sound or movie file to play.
Open the Property Inspector for the player and click the button next to the Source (1), this allows you to select an external file to be played.
You can also set the filename property of a player in script, for example:
set the filename of player "sound" to "G:/Documents/Elanor/Projects/Getting Started Lessons/hiscore.m4a"
Using the Player Controller
The controller that appears at the bottom of the player allows the user to start and stop play back(1), control the volume(2) and move to a certain point in the sound file or movie(3,4).
Controlling the Player in Script
If you don't want your users to have control of the video, or you prefer not to show the controller and add your own objects to control play back, then you can use LiveCode scripts to control the video.
Open the Property Inspector for the player and turn off the controller (1). Name your player "Movie" in the Name field (2). Create and name some buttons to control the player (3).
In the Play button script enter:
on mouseup start player "movie" end mouseup
In the Stop button enter:
on mouseup stop player "movie" end mouseup
Switch to edit mode and try it out, your movie should start and stop.
You can check what other commands and properties are available to you in the Dictionary. Check the entry for the Player Object. For example you can set the currentTime property -
Specifies the elapsed time in a movie or sound, by setting this you can skip forward or back e.g.
set the currentTime of player "movie" to 12000
Referencing Files on a Server
You can also set the filename property of a player to an http URL.
Save your sample stack, then open the script editor for the card by right clicking on the card outside your player or buttons. Add this to the card script:
on preopencard set the filename of player "movie" to "http://elanorb.on-rev.com/lessons/MalteBrill.mp4" end preopencard
Close your stack after saving, then reopen it. The script will run before the card opens, and populate your player with the movie indicated.
If you specify a URL for a streaming QuickTime movie file, LiveCode displays the movie sequentially as it downloads. Otherwise, LiveCode must download the entire file before you can play it. To pre-fetch a file from the Internet in order to speed up access to it, use the load command before visiting the card that holds the player or image that references the file's URL. You could add this to your preopencard script.
Using Players on Mobile
This lesson only applies to players on the desktop. If you want to use a player in a Mobile application you can use an iosPlayer or androidPlayer object, this is a native mobile control that displays a movie. For more information on using mobile players see the lesson "How do I play a video in part of the screen on mobile".
- .aifc and .cdda
- .aif and .aiff
- .m4a (=Apple m4a audio file format)
- .wav, .wave, and .bwf
- .au and .snd
- .m4v (=iTunes video file format)
- .mov and .qt (=QuickTime movies) WAVE audio file format.
Windows (DS Player)
With appropriate codecs/filters you can play most files. LAV Filters are popular amongst community members.