Runtime Revolution
Articles Other News

Creating Rich Media Applications with Callbacks
by Elanor Buchanan


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:

intervalNumber, messageName

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.

For example:

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
end showPicture

on displaySubtitle pText
put pText into field "subtitle"
end displaySubtitle

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"
end hiliteWord

You might have the following callbacks on player "voiceover":

  • 1500,showPicture "Storybook.jpg"
  • 1800,displaySubtitle "Once upon a time"
  • 2000,hiliteWord

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.


6th July 2006

Revolution and U3

Building CGI's with Revolution, part 1

Reflections From RevCon

Arcade Engine

How to Contribute to this Newsletter

editorial staff

We would like to have your contributions. We are gathering topics for future newsletters. Please write to us about your projects, activities and tips you have learned. Let us know what you would like to have featured in future issues as well. If you have ideas about how to grow the community share that as well.

This newsletter is moving to a mailman list for administrative purposes. You can subscribe, unsubscribe and change your preferences here.

©2005 Runtime Revolution Ltd, 15-19 York Place, Edinburgh, Scotland, UK, EH1 3EB.
Questions? Email for answers.