[adoberuntime]Adobe Media Server 4.0, Flash Player 10.1[/adoberuntime]

About fast switch

Use the NetStreamPlayOptions.offset property to tell the server when to switch between streams of different bitrates. The offset is the time, in seconds, at which the streams switch.

The default value of offset is -1, which is the fast switching mode. In this mode, switching occurs at the first available keyframe after netstream.time + 3, which is about 3 seconds later than the playback point.

Note:

Best practice for fast switching is to set NetStream.bufferLength to 10 seconds and NetStreamPlayOptions.offset to 3, 4, or 5 seconds.

Any data buffered from a previous stream is flushed. Fast switch is faster than standard switch mode because clients don’t have to wait for buffered data to play.

To use standard switch mode, set offset to a value greater than the buffer (offset > NetStream.time + NetStream.bufferLength).

Writing the fast switching code

Use the NetStreamPlayTransitions.SWITCH constant to trigger stream switches. Use the NetStreamPlayOptions.offset property to specify the absolute stream time at which the switch occurs. The offset property is absolute stream time, it is not an offset from the playback point. For example, to switch 5 seconds from the playback point, set the offset property to netstream.time + 5, not to 5.

var ns:NetStream = new NetStream(nc); 
var nso:NetStreamPlayOptions = new NetStreamPlayOptions(); 
nso.streamName = streamName; 
nso.transition = NetStreamPlayTransitions.SWITCH; 
nso.start = 10; 
nso.len = -1; // play until the end of the file 
nso.offset = ns.time + 5; // switch 5 secs. after the playback point. 
ns.play2(nso);

Note:

The default value of offset is netStream.time + 3. The default value causes the server to switch the stream 3 seconds after the playback point.

NetStatus events for fast switching

NetStatus Event

Description

NetStream.Play.Failed

The value of offset is less than the current playhead time.

The stream cannot switch.

NetStream.Play.Transition

A SWITCH call was made successfully and the server starts streaming data for the new stream.

NetStream.Play.TransitionComplete

A new stream starts playing.

In fast switching mode, the time between the NetStream.Play.Transition event and the NetStream.Play.TransitionComplete event is much shorter than in standard switching mode.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy