ActionScript Video Extensions

There are a number of ActionScript methods built into Flash which Scaleform supports for playing video files. Additionally, there are several new extensions specific to Scaleform. Search the Adobe help files for ‘NetStream’ to view more information on the built-in NetStream properties, methods, and events. Also, please refer to Flash Support Overview for complete list of built-in methods supported by NetStream and Video classes.

Supported Built-in NetStream Properties

currentFps:Number

The number of frames per second being displayed.

    Example: var currentFps:Number = ns.currentFps;

time:Number

The position of the playhead, in seconds.

Example: var currentTime:Number = ns.time;

Supported Built-in NetStream Events

onCuePoint = function(infoObject:Object) {}

Invoked when an embedded cue point is reached while playing a USM file.

NOTE: Search ‘onCuePoint’ in Adobe Flash Help for more details.

onMetaData = function(infoObject:Object) {}

Invoked when the player receives descriptive information embedded in the USM file being played.

NOTE: Search ‘onMetaData’ in Adobe Flash Help for more details.

Scaleform Extensions:

audioTracks

An array of audio tracks in the USM file.

Example:

ns.onMetaData = function(infoObject:Object)
{
    audioTrackArray = infoObject.audioTracks;
}

subtitleTracksNumber

The total number of subtitle tracks in a USM file.

Example:

ns.onMetaData = function(infoObject:Object)
{
        numSubtitleChannels = infoObject.subtitleTracksNumber;
        trace("Subtitle Channels: " +  numSubtitleChannels);
}

onStatus = function(infoObject:Object) {}

Invoked every time a status change or error is posted for the NetStream object.

NOTE: Search 'onStatus' in Adobe Flash Help for more details.

Supported Built-in NetStream Methods

close()

Stops playing all data on the stream, sets the ns.time property to 0, and makes the stream available for another use.

Example: ns.close();

pause([flag:Boolean])

Pauses or resumes playback of a stream.

Example: ns.pause(true);

play(name:Object, start:Number, len:Number, reset:Object)

Begins playback of an external video (USM) file.

Example: ns.play("myVideo.usm");

seek(offset:Number)

Seeks to the keyframe closest to the specified number of seconds from the beginning of the stream.

Example: ns.seek(50);

setBufferTime(bufferTime:Number)

Sets the amount of movie data that will be buffered, in seconds. GFx::Video::Video buffers enough data from disk to allow for smooth playback and to reduce disk reads. The buffer size is based on the bitrate of the video, and other video parameters. By default, this buffer will be large enough to hold 1 second worth of playback.

Example: ns.setBufferTime(2.5);

New Scaleform NetStream and Video Extensions

subtitleTrack = Number

The current subtitle track number being used by the NetStream.

Example:  ns.subtitleTrack = 1;

audioTrack = Number

The main audio track used by the NetStream. When a video file has multiple audio tracks (e.g., an English version and a Spanish version), this can be used to set the audio track for specific language.

Example: ns.audioTrack = 2;

subAudioTrack = Number

A secondary or SubAudio track, which is typically used by the NetStream to play a dialog track or sound effects along with a movie.

Example: ns.subAudioTrack = 3;

voiceTrack = Number

Replaces the center track of 5.1ch audio. Use this only to change the voice track of 5.1ch music.

Example: ns.voiceTrack = 1;

setReloadThresholdTime(reloadTime:Number)

Sets the re-load timing. Determines how often the video data buffer is refilled from disk. For instance, if an application sets the buffer size to 4 seconds (with setBufferTime), and sets the reload threshold to 1 second, then GFx::Video::Video will initially fill the buffer with 4 seconds worth of data. After 3 seconds worth of data have been decoded and consumed, there will be less than reload threshold seconds of data remaining, and GFx::Video::Video will refill the buffer.

Example: ns.setReloadThresholdTime(1);

setNumberOfFramePools(numPools:Number)

Sets the number of internal video buffers. GFx::Video::Video uses internal memory to buffer decoded frames before display. More frame pools can help smooth out playback under high CPU loads. Default value is 2.

Example: ns.setNumberOfFramePools(3);

setOpenTimeout(timeout:Number)

Sets open file timeout (time necessary to decode USM header) in seconds. Default value is 5 sec. To disable this feature (set infinite timeout) pass 0.

Example: ns.setOpenTimeout(5);

currentFrame:Number Returns current playback position (in frames).

Example: trace("Current FPS: " + ns.currentFps + " fps");

loop = Boolean

Setting loop to true tells the NetStream to loop the video until loop is set to false.

Example: ns.loop = true;

onSubtitle = function(msg:String) {}

Invoked when the player receives a subtitle string from the USM file.

Example: ns.onSubtitle = function(msg:String) { trace(msg); }

clipRect = new rectangle(x:Number, y:Number, width:Number, height:Number)

Used to display only a given rectangular region of the video.

Example: ns.clipRect = new rectangle(100, 100,  240, 200);