Loading Video Files When a User Selects a Video From the Menu

Now that the video menu is being populated we need to have the application load a video whenever the user selects a video in the menu. Let's look at how to do that.

Edit Card Script

Edit Card Script

With the Video Player Stack window at the forefront, choose Object > Card Script to edit the card script of the Stack window again.

Define The uiLoadSelectedVideo Handler

Define The uiLoadSelectedVideo Handler

To start we need to define a command that will load the video file that is selected in the menu. uiLoadSelectedVideo will do just that. It gets the video file that is selected and creates a path to the video (1) that looks like this:


Note that the path to the video is a relative path rather than an absolute path. When you assign a relative path to the filename property of a Player object Revolution will try to locate the relative path using the folder that the stack file resides in as well as 'the default folder'. Since the Videos folder is alongside the stack file Revolution is able to find videos using the above relative URL.

Note for those using older versions of Revolution: Searching the folder that the stack file resides in in order to locate movies was added in Revolution 3.5. If you are using an older version of Revolution then you will need set the defaultFolder property to the folder the stack file is in.

Copy & Paste Into Card Script

command uiLoadSelectedVideo

## Get the name of the video selected in the video menu

put the selectedtext of field "Video Menu" into theVideoName

put "Videos/" & theVideoName into theVideoFile

## Set 'the filename' property of the player object to the relative video path

## Revolution will locate the video as long as the "Videos" folder is

## alongside the stack file or the application executable.

set the filename of player "My Video" to theVideoFile

## Reset the time of the Player object to 0

set the currenttime of player "My Video" to 0

end uiLoadSelectedVideo

Compile The Card Script

Compile The Card Script

Click the Compile button to save the changes to the Card script.

Edit the List Field Script

Edit the List Field Script

Now we just have to tell Revolution that we want the uiLoadSelectedVideo command to be called whenever the user changes the selected  menu item in the video menu. With the Edit tool activated (1) select the Video Menu List Field (2). Click on the Script button in the toolbar (3) to edit the object's script.

Define selectionChanged

Define selectionChanged

Whenever the user selects a line in a List Field Revolution sends a message to the field indicating that the selection has changed. This message is called selectionChanged. You can define what happens when this message is sent to the field by defining the on selectionChanged message in the field's script.

Remember that a Card script can have revTalk that affects all objects on a card. Since we have already defined the uiLoadSelectedVideo command in the Card Script we can call that command from the selectionChanged message of the List Field Script.

Copy & Paste Into List Field Script

on selectionChanged


end selectionChanged



After adding the above script to the List Field and pressing the Compile button you can test your work. First activate the Browse tool.

With the Browse tool activated you can try selecting different selections in the video menu. As you make different selections the video in the Player object should change.

Troubleshooting: If Video Doesn't Show Up

Troubleshooting: If Video Doesn't Show Up

If the video doesn't show up in the Player object then check the Object Inspector for the Player object. Make sure the Source field (the Source field shows the 'filename' property of the Player object) contains a valid relative path.


Peter W A Wood

I experienced a problem displaying the videos. The 'filename" of the video was correctly set. The problem was that the defaultFolder was set to the folder containing the Revolution IDE executable not the stack.

I changed the defaultFolder to the one containing the stack using the Message Box, it then correctly displayed the video in the player.

Saving the stack also saves the change to the defaultFolder.

Trevor DeVore

@Peter Searching the folder the stack is saved in for the movie file was added in Revolution 3.5. I've updated the lesson to mention this.

Stephanie East

When I test this, my video fills my window and hides the video list box. When the video stops playing it stays on the screen and I can't get back to the video list.

Trevor DeVore

@Stephanie: Take a look at the lockLocation property. By default, when LiveCode opens a card containing an image or player, the image or player object is resized to fit the size of the media. If you want to force the image or player object to maintain a certain size then you need to use the lockLocation property.



@Trevor: that worked thanks for the help.

Jake E

I had trouble displaying my video. My video would be on the window, but when I used the "Browse" tool and click on my video in the video list box, the video would go blank.

Trevor DeVore

@Jake: After clicking on video in the list field what does the property inspector say the filename property of the video object is? Does it contain a valid relative path?

edgar ruiz

there's any way to switch player fullscreen? can player normalize audio?.. thanks in advance

Hanson Schmidt-Cornelius

Hi Edgar,

yes, it is possible to make the player take up the entire screen, but the way you do it depends on the platform you are using. Have a look at iphoneControlSet for iOS. On desktop you can use the QuickTimePlayer control. Set the player to the size of the stack and resize the stack to the size of the screen.

Sound normalization is not build into the players.

Kind Regards,


Add your comment

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