Note: This lecture is intended to accompany the stack "QTPlayerLecture.rev", which can be found in the Lectures folder on the class file server. Remember you can also open it using the Revolution command:
go to stack URL "http://chum310.byu.edu/Lectures/QTPlayerLecture.rev".
![]() |
Revolution includes a very versatile Player object that gives you a high degree of control over the playback of QuickTime movies in your stack. The first step is to create a QuickTime Player object in your stack. The tool for this object is found on the bottom right-hand corner of the Tools palette. Just as with all other objects, you simply click the tool and drag a new player object onto the card, then drag to the size and shape you want the object to assume. Note: When you first create the new player, it will display a “dummy” blank movie that is a common size and shape for QuickTime videos. However, the various types of media you might want to display in your player object may vary, and the player object will automatically change its height and width to fit the size of the media file it is displaying. Once the object is created, it is a good idea to give it a simple name,
since you will need to refer to it often in scripting. I'll use the name
"qt", so the full reference to this object is |
Completing three simple operations will allow you to quickly open and play a movie in your new player object:
1. Choose the movie file: It is simple to
assign a movie to the player object, by just changing its filename
property:
set the filename of player "qt" to "simplemovie.mov"
Just as with other commands, notably the put url and the open file, read, write, and
close file commands, referring to an external movie file by name
only, as above, will assume that the movie file resides in the defaultFolder.
To open a movie from some other location, specify the entire file path:
set the filename of player "qt" to "/MyHD/Movies/simplemovie.mov"
A convenient way of allowing the user to select the movie they want to open
is to use the answer file command. For example, you could create
a button with the following handler:
on mouseUp
answer file "Choose a movie file to play:"
if it is empty then
exit mouseUp
end if
set the fileName of player "qt" to it
end mouseUp
This will put the entire filepath of the movie file into the player's filename
property.
2. Play the movie: Use the start command:
start player "qt"
3. Stop the movie: Use the equally simple stop command:
stop player "qt"
Another simple way to pause and resume the movie is to use the
paused property:
set the paused of player "qt" to true -- (or false)
By putting the following command in a button's script you can pause and resume play by clicking on just one button:
set the paused of player "qt" to not the paused of player "qt"
That's all there is to opening and playing a movie in Revolution. Of course, there are a lot more capabilities, which allow you to change the appearance and behavior of the movie being played.
A player object has the same basic properties that all Revolution objects have.
For instance setting the visible, the rectangle, the height, the width,
the showBorder and other properties will all have the expected outcome.
Try it out on your own.
set the visible of player "qt" to not the visible of player "qt" --will alternately hide and show the player
set the location of player "qt" to 400,300 --remember that thelocof the player is the center of the player window
set the height of player "qt" to fld "heightFld" --where fld "heightFld" has a valid integer in it
set the width of player "qt" to fld "widthFld" --where fld "widthtFld" has a valid integer in it
set the top of player "qt" to the bottom of fld "playerLbl"
set the showBorder of player "qt" to not the showBorder of player "qt" --alternately shows and hides the border of the player object
|
Just like other object types, the Player object has its own set of unique properties. We won't go into all of them in depth (you can look any of them up in the Transcript Dictionary if you are curious). Instead, let's look at the most commonly used and useful properties.
|
currentTime - contains the current frame number of the
movie.
set the currentTime of player "qt" to 1200 --shows the frame that is 2 seconds from the beginning of the movie (based on a frame rate of 600 frames/second.)
timeScale (labeled as "Units/sec") - a read-only
property that gives the time scale of the currently-loaded movie in number of
frames per second. Most QuickTime video movies have a rate of 600 frames per
second.
duration - a read-only property that gives the total number
of frames in the movie, based on the timeScale. If you divide this
number by the timeScale, you get the length of the movie in seconds.
0 -1 paused play backward normal speed Examples: By using the last three properties in conjunction with one another, we can
choose to play very specific sections of a larger movie. The following sequence
of commands will cause only the indicated segment to play: The callbacks list at the bottom of the player properties palette lets you
specify messages that will be sent at the specified time indices. In this example the message In addition to the callbacks you set in the callback list, there are two messages
that automatically get sent when certain events happen: The Tracks panel in the properties palette, contains properties that determine
how many and what kind of tracks the
movie contains, and indicates which tracks are currently enabled. Every
QuickTime movie has one or more tracks. At any given time any
of these tracks can be separately enabled or disabled. You can disable
a track
by selecting it and un-checking the "Track is Enabled" checkbox.
When a track is disabled it will not play when the move is playing.
For instance,
if the Sound track is disabled the video will play with no sound. Conversely,
if the Sound Track is enabled but the Video track is disabled, the audio
only will play. Two properties help you manage the tracks in your movie: places something like the following results in the message box: places something like the following in the message box: If I wanted to enable the video track only I would do this: To re-enable the sound track, I'd have to set the property again: Finally, if you just want to check what types of media tracks your movie contains use:
Using the commands, properties and messages detailed above, you can create
sophisticated mulimedia applications in Revolution.playRate - this property determines the speed and direction
the movie is playing according to the following chart:
1
0.1 to 0.9
greater than 1
-0.1 to -0.9
less than -1
play forward normal speed
play forward slow
play forward fast
play backward slow
play backward fast
set the playrate of player "qt" to 1 -- play forward,
normal
set the playrate of player "qt" to -10 -- fast reverse
showSelection - If set to true, indicates in the controller
bar the selected segment, as determined by startTime and endTime.playSelection - If set to true, only the segment from startTime
to endTime will play.startTime - the beginning of a segment of the movie; the
"in" point.endTime - the end of a segment of the movie; the "out"
point.
set the startTime of player "qt" to 20400
set the endTime of player "qt" to 32432
set the playSelection of player "qt" to true
start player "qt"
Callbacks—Synchronizing other events to movie playback

firstMessage will be sent one
second (600 frames) into the movie. The message nextOne will
be sent 3.3 seconds into the movie, at frame number 2000. By putting appropriate
handlers in the player's message hierarchy (for example, in the script
of the player object itself or in the script of the card it's on) you
can execute desired commands at the specified times:
on nextOne
put "The man is leaving for work." into
fld "comment"
end nextOne
playStopped - sent to the player whenever it stops playing,
including when the movie reaches its end.playPaused - sent to the player whenever the user pauses the
movie.
Movie Tracks properties

the tracks - this read-only property gives information
about all of the tracks in your movie, as shown in the tracks list in
the properties palette. For example, the following command:
put the tracks of player "qt"
2,Video,0,3739
5,Sound,0,3720
8,Sprite,0,600the enabledTracks - this property stores the ID numbers
only of the tracks that are currently enabled in the movie. This command:
put the enabledTracks of player "qt"
2
5
set the enabledTracks of player "qt" to 2
set the enabledTracks of player "qt" to 2 & return
& 5mediaTypes - this read-only property will tell you
what kind of media tracks are contained in the movie.Assignment: Using QuickTime Movies In Revolution
Back
CHum Revolution Gateway
Copyright © 2005 Brigham Young University