NetStream class offers four main methods for controlling video playback:
: Pauses playback
of a video stream. If the video is already paused, calling this
method does nothing.
: Resumes playback
of a video stream that is paused. If the video is already playing,
calling this method does nothing.
: Seeks the keyframe
closest to the specified location (an offset, in seconds, from the
beginning of the stream).
: Pauses or
resumes playback of a stream.
There is no
In order to stop a stream you must pause playback and seek to the
beginning of the video stream.
method does not
resume playback, it is used for loading video files.
The following example demonstrates how to control a video using
several different buttons. To run the following example, create
a new document and add four button instances to your workspace (
var nc:NetConnection = new NetConnection();
var ns:NetStream = new NetStream(nc);
// ignore error
var vid:Video = new Video();
// Pause the stream and move the playhead back to
// the beginning of the stream.
Clicking on the
button instance while
the video is playing causes the video file to pause. If the video
is already paused, clicking this button has no effect. Clicking
button instance resumes video playback
if playback was previously paused, otherwise the button has no effect
if the video was already playing.
Detecting the end of a video stream
to listen for the beginning and end of a video stream, you need
to add an event listener to the NetStream instance to listen for
event. The following code demonstrates
how to listen for the various codes throughout the video’s playback:
The previous code generates the following output:
The two codes that you want to specifically listen for are “NetStream.Play.Start” and
“NetStream.Play.Stop” which signal the beginning and end of the
video’s playback. The following snippet uses a switch statement
to filter these two codes and trace a message:
trace("Start [" + ns.time.toFixed(3) + " seconds]");
trace("Stop [" + ns.time.toFixed(3) + " seconds]");
By listening for the
can build a video player which loads the next video in a playlist
once the current video has finished playing.