Recipe 16.5. Controlling Playback Time


Problem

You want to control the playback of a video.

Solution

Use the seek( ) method of the NetStream object.

Discussion

Although you may assume you can set the playback time by assigning a value to the time property of the NetStream object that controls the video, that won't work. As mentioned in Recipe 16.3, the time property is read-only. Rather, you must use the seek( ) method. The seek( ) method requires one parameter to specify the number of seconds from the start of the video to which you want to move the playback. The following example seeks five seconds from the start of the video before starting the playback:

videoStream.seek(5);

When using seek( ) with progressive download video, you can seek to only a part of the video that has downloaded. For example, if half of a 60-second video has downloaded, you can seek to 10 seconds, but you cannot seek to 50 seconds.

When you use seek( ), Flash Player jumps to the nearest video keyframe to the value you specify. Videos are encoded with different keyframe rates. Higher keyframe rates have larger bandwidth requirements than lower keyframe rates. However, higher keyframe rates enables greater granularity when seeking.

See Also

Recipe 16.12




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net