14.8. Creating Playlists
Problem
You want to create a playlist in which streams are queued and played one after another.
Solution
Use the NetStream.play( )
method
to add streams to the playlist. Specify
false
for the
flushPlaylists
parameter.
Discussion
You can create playlists for net streams relatively quickly and
easily with built-in functionality. The NetStream.play(
)
method allows you to create playlists by simply
appending new streams with each subsequent play(
)
invocation. However, the default behavior is for
play( )
to flush the current playlist. To avoid
flushing the existing playlist, specify false
for
the optional fourth parameter,
flushPlaylists
. You can use -2 and -1 as
placeholders for the intervening start
and
length
parameters to maintain the default
behavior:
// Add three streams to a net stream object's playlist. mySubscribe_ns.play("stream0", -2, -1, false); mySubscribe_ns.play("stream1", -2, -1, false); mySubscribe_ns.play("stream2", -2, -1, false);
Flash automatically begins playback of the next stream in the
playlist when the current stream stops, which depends on the values
specified for the start
and
length
parameters. These parameters are
discussed in Recipe 14.7.
You can create a new playlist at any time by calling play(
)
with a value of true
for the
flushPlaylists
parameter. This flushes the
current playlist, stops the current stream, and plays the new stream.
mySubscribe_ns.play("stream3", -2, -1, true);
Omitting the fourth parameter performs the same operation: ...
Get Actionscript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.