Players are a great feature of Revolution, they can play audio or video allowing you to create rich media applications. Players can be stopped, paused, rewound - all the abilities you would expect of any media player - but one of the features that makes Revolution players really powerful is callbacks.
Callbacks are a property of a player and are a list of entries, one per line, which allow you to trigger scripts at specific points during playback.
Each entry has the form:
The intervalNumber is a positive integer expressed in the internal player time format, this depends on the timescale of the player where the timescale is the number of intervals per second. In a player with a timescale of 500 interval 1000 would be 2 seconds into the movie or sound.
The message messageName is sent when the currentTime of the player reaches the given interval, allowing the user to synchronize other actions with the playback of a movie or sound file.
One possible application of callbacks would be to create a talking storybook, a fun and educational program for children learning to read or a foreign language teaching tool. Callbacks can be used to change the graphics as the story is being read and show the text along with the voiceover, the
color of individual words can be changed in time with the voice to make it easy to follow.
To use callbacks to display text and graphics, you simply identify the intervals where you want them to change and set the callbacks of the player to send a message when it reaches those intervals.
On your card place
- A player called "voiceover"
- An image called "picture"
- A field called "subtitle"
In your card script, write
on showPicture pFilename
set the filename of image "picture" to pFilename
on displaySubtitle pText
put pText into field "subtitle"
on hiliteWord pWordNumber
resetWordColors -- this would set the colors of all the words in the field to the unhilited color
set the textColor of word pWordNumber of field "subtitle" to "red"
You might have the following callbacks on player "voiceover":
- 1500,showPicture "Storybook.jpg"
- 1800,displaySubtitle "Once upon a time"
When the currentTime of player "voiceover" reaches 1500 intervals, the showPicture handler is called and the graphic "Storybook.jpg" is shown; 200 intervals later the words "Once upon a time" are displayed in the field "subtitle" and when the currentTime of player "voiceover" reaches 2000 the word "upon" is hilited in red.
There are a number of ways you could set the callbacks of your player. They could be read in from external text file, stored as a custom property of your stack or set using the object inspector.
For further information check the Revolution Documentation on player objects, the callbacks property and the timescale property.