DekGenius.com
[ Team LiB ] Previous Section Next Section

Recipe 14.11 Pausing and Resuming a Net Stream

14.11.1 Problem

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

14.11.2 Solution

Use the NetStream.pause( ) method.

14.11.3 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, one of two things can happen:

  • If you specify false for the flushPlayLists parameter, the stream is added to the playlist, and it begins playing only after any existing streams in the playlist have finished.

  • If flushPlayLists is undefined or true, the stream begins playing again from the specified starting point. Technically, you could use this to try to seek the stream. However, this would be very inefficient because each time play( ) is called, the stream is requested from the server.

You can pause and resume any stream, even live streams. However, when you pause a live stream, it resumes at the current (realtime) position, not at the point where the stream was paused.

14.11.4 See Also

Recipe 13.3, Recipe 14.8, and Recipe 14.12

    [ Team LiB ] Previous Section Next Section