Using Players

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

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

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

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

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

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".

Supported Formats

Mac (AVPlayer)

Audio:

  • .aifc and .cdda
  • .aif and .aiff
  • .caf
  • .m4a (=Apple m4a audio file format)
  • .wav, .wave, and .bwf
  • .amr
  • .ac3
  • .mp3
  • .au and .snd

Video

  • .m4v  (=iTunes video file format)
  • .mp4
  • .mov and .qt  (=QuickTime movies) WAVE audio file format.

Windows (DS Player)

https://docs.microsoft.com/en-us/windows/desktop/directshow/supported-formats-in-directshow

With appropriate codecs/filters you can play most files. LAV Filters are popular amongst community members.

17 Comments

Ian Stewart

Hello

I have a player and use it to play quicktime movies.

The code in the program refers to a file ending in ".mov".

The uncompiled and compiled (standalone) versions work fine on my PC with XP.

However the standalone does not seem to play the files when I put the standalone (including the resource folder) on a PC with windows 7.

The file extension (".mov") is not visible as an ending on this platform so I wondered if that might be the problem? If so, what can I do to get around this?

Thanks
Ian

Hanson Schmidt-Cornelius

Hi Ian,

you can control the extensions of your files in your "Explorer preferences". Have a look at Tools -> Folder Options... -> View. You should then find a line with a tick box that states: "Hide extensions for known file types". If you untick this, you should see the .mov extensions again.

Making the .mov extension visible will probably not help address the problem you are having, but without more information it is hard for me to make any recommendations on what may be wrong.

You could research if someone else has had a similar issue in our LiveCode community on one of our forums: http://forums.runrev.com/, contact support at [email protected] or launch a but report in our quality control centre at quality.runrev.com. We would be very happy to look into the issue if you think something is not working the way you think it should.

Kind Regards,

Hanson

Geoff Macumber

Hi,

I have been trying to get a video player to work but with no success. I have done everything shown above but no result. Can I get some sample code for a simple stack that works so that I can compare with what I am doing to see what is wrong please?

Elanor Buchanan

Hi Geoff,

Using player objects on desktop apps doesn't really require any code, you just add a player object, set its filename property to reference the video file you want to play and then use the player controls to start and stop the player.

What type of video file are you trying to play and what platform are you working on?

Kind regards

Elanor

Mark Hinnebusch

I am assuming that it is not possible to use a player to play an audio clip object that has been imported into the stack as a control. I would like to be able to pause/resume and get the duration of the audioclip but it appears those functions are only available on a player, not just using the play audioclip. Does anyone know of a workaround? or am I missing something?

thanks, in advance.

Elanor Buchanan

Hi Mark, yes you are a bit more restricted with what you can do with audioclips, really just playing and stopping. If you want to use a player you can include the sound file with your app and use specialFolderPath("resources") to get the path to the file.

I hope that helps.

Kind regards

Elanor

Ethan Robertson

Hi, is there a reason why my WMV files on a player will randomly stop mid-way during a video? I'm using LC 9.0.0 on Windows 7 and/or Windows 10. One video I tried stopped at a minute, the other only a few seconds -- both clips are over two minutes long. When they stop, if you hit the play button, the video just restarts. It's almost as if the player thinks it has reached the end of the video when it can sometimes only be a few seconds into a two-minute long clip. Can anyone help?

Elanor Buchanan

Hi Ethan

That sounds like is could be a bug. Could you report it at

https://quality.livecode.com/

From there it will be picked up and investigated.

Kind regards

Elanor

Will Cate

Player also supports FLAC audio (Mac OS Big Sur, LiveCode 9.6.3) HOWEVER the file picker in the Player Inspector doesn't recognize .flac files unless "All Files" option is selected.

Roy

When I use the player and close to Windows. For a person who doesn't have "livecode" it doesn't work and shows a white screen! I checked which 5 users. help?

Panos Merakos

Hello Roy,
Could you please share your .livecode stack? What is the filename property of the player? You can upload your stack to WeTransfer and post the download link here.
Kind regards,
Panos

Roy Fania

Remember that if you have Livecode installed on your computer, the player will work.
If Livecode is not installed, a stuck white screen will be displayed when the application is closed to Windows.

Link :

https://we.tl/t-cQ9bmwbWRY

Mark Wieder

The discussion is here: (spoiler alert... it's justt a matter of installed codecs) https://forums.livecode.com/viewtopic.php?f=8&t=37372

Panos Merakos

Oh right - missing codecs :) Thanks Mark.
So @Roy you need to install the missing codecs in the target machines. You can try installing the LAV Filters, hopefully this will fix the issue :)

Kind regards,
Panos

Roy

I installed. It still does not work. Although the player is running. But does not play the video. In order to best understand what is happening, I suggest you try to put software with a player on a computer without livecode in addition to LAV Filters

Raul Mendoza

Using the player control in ubuntu 18.04 32bit dont show the controller, only a square form and can not use the play command, also the only filetype is mov.

Panos Merakos

@Raul

Unfortunately the player object has some issues on Linux. See this bug for more details:

https://quality.livecode.com/show_bug.cgi?id=18757

Kind regards,
Panos

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.