Recipe 16.11.
Stopping Video
Problem
You want
to stop a video from playing and downloading.
Solution
Use the close( ) method of the
NetStream class.
Discussion
When you want to stop a video from playing back,
use the close( ) method of the NetStream object that
controls the video. When you use the pause( ) method, the
video simply pauses and starts playing again (typically when a UI
button is pressed by the user), but even when paused, the FLV data
continues to download. If you want to completely stop a video from
downloading, use the close( ) method, as follows:
videoStream.close( );
When you call the close( ) method, Flash
Player deletes the FLV data from the player. If you request the
video again, it needs to start the download all over again. It is
possible, however, that a web browser might cache the FLV, and
subsequent requests to the same FLV might retrieve the cached
version. In such instances, subsequent requests for the same FLV
would be faster to playback. However, if an FLV is cached, it's
possible that a user might see a cached version rather than an
updated version. To ensure that the user always sees the latest
version of the FLV, append a unique query string to the FLV request
URL, as shown in the following example:
videoStream.play("video.flv?uniqueIndex=" + (new Date( )).getTime( ));
If you don't want a video to be cached for
digital rights purposes, you cannot use progressive download video.
In such cases, you need to stream the video by using a technology
such as Flash Media Server, which is outside of the scope of this
book.
|