Repeat a Clip Sequentially for a Set Amount of Time
Clips can be repeated sequentially for certain length of time by the placement of two scripts within the clip itself. The first Script is placed at the beginning of the Clip, and records the starting time of the first repeat of the Clip in a Clip Custom Property. The second Script is placed at the end of the Clip, and measures the elapsed time at the end of each repeat. If the desired amount of time has passed, it causes the Clip to stop repeating.
The Clip is set to repeat for a very large number of repeats, so that it will repeat forever until the second Script stops it. Alternatively, a number could be set as the maximum, for example if you wanted to repeat for "n times or until m seconds have passed, whichever comes first".
Note that any number of Messages or other Clip Elements could be between the two Scripts. This example contains a Delay simply to make the example not generate too much data.
The composition contains a test clip with a large number of repeats.
The Record start time script source is presented here.
// Is this the first repeat of this Clip?
if ($context.currentClipIndex == 0)
// This is the first repeat of this clip.
// Get the Clip's property list.
var propList = $context.currentClip.propertyList;
// Create the "StartTime" property, ignoring any errors
// if the property already exists.
// Set the property value to the time of this, the first
// repeat (in milliseconds since January 1, 1970).
The Check elapsed time script source is presented here.
// Get the startTime that was set by the "Record start time" Script, from the
// Clip property that it was placed into.
var startTime = $context.currentClip.propertyList.getPropertyValue("StartTime");
// Compute the elapsed time that has passed since repeating started (in milliseconds).
var elapsedTime = Date.now() - startTime;
// If it has been more than 30 seconds since the Clip started, terminate the repeating
// of this Clip.
if (elapsedTime > 30000)