O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.11. Pausing and Resuming a Net Stream

Problem

You want to control the playback (pause or resume) of audio and/or video that is being played from a net stream.

Solution

Use the NetStream.pause( ) method.

Discussion

You can use the NetStream.pause( ) method to pause the playback of a net stream. For example, if a net stream is playing, the following line of code pauses its playback:

myNetStream.pause(  );

However, the pause( ) method, when used without a parameter, acts as a toggle between pausing and resuming playback. If the net stream in the preceding example is already paused at the time that the pause( ) method is invoked, the stream begins playing again at the point where it left off.

Alternatively, you can specify a Boolean parameter to indicate whether the net stream should pause or resume, regardless of its current state. A value of true causes a net stream to pause if it is playing or to remain paused if it is already paused. On the other hand, a value of false causes the net stream to resume playing if it is paused or to continue playing if it is already playing. For example:

// Cause a net stream to pause.
myNetStream.pause(true);

// Cause a net stream to play.
myNetStream.pause(false);

The play( ) method should not be used to resume the playback of a net stream, nor should it be used to fast-forward or rewind (see Recipe 14.12). The play( ) method retrieves a stream from the FlashCom server and adds it to a client’s net stream for playback. If you call play( ) more than once, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required