This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
166
|
Chapter 5: Managing Streams
Stop-motion video can be done in a similar way. Instead of using setInterval( ) to
capture a frame at regular intervals, a single frame can be captured and appended to
the recorded stream whenever a button is clicked. Unlike normal video capture,
every frame in a time-lapse or stop-motion video stream is a complete frame (a video
keyframe, not a so-called difference frame that contains only the delta between two
successive frames). Time-lapse and stop-motion videos will normally require much
more bandwidth than regular video and should be buffered accordingly. Each appli-
cation is likely to be different, but you should try experimenting with a buffer 10
times larger than you might otherwise have used.
Playing Streams in Detail
The NetStream.play( ) method can be used to play live and recorded streams, seg-
ments of recorded streams, and a playlist of streams. The play( ) method has a num-
ber of optional parameters that make this possible:
in_ns.play(streamURI | false, [, start [,length [, flushPlaylists]]]);
The first parameter is required and must be either a relative URI that identifies the
stream to play or the value
false, which stops the current stream from playing. The
remaining parameters, shown inside square brackets, are optional. The nesting of the
square brackets indicates that if one optional parameter is included, then so must all
previous ones. For example, to use the
length parameter, the start parameter must
also be provided.
Playing Live or Recorded Streams
The start parameter can be used to indicate more than its name implies. The possi-
ble values for
start are:
-2
Plays the live stream at the specified URI or plays the recorded stream at that
location if the live stream is not found. If a recorded stream is also not found, the
NetStream object waits for the stream to be published.
-1
Plays only a live stream at the specified URI. If a live stream is not found, the
NetStream object waits for one to be published. A recorded stream at the same
URI will not be played.
0
Plays only a recorded stream at the specified URI from its beginning. If a
recorded stream is not found, an information object is returned to NetStream.
onStatus( ).
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Playing Streams in Detail
|
167
Greater than 0
Same as passing 0, but indicates how many seconds into the recorded stream to
begin playing.
If a
start value is not passed into the play( ) method, the default is -2 (plays a live or
recorded stream).
The
length parameter defines how many seconds the live or recorded stream should
play. For example, to play a stream beginning 1 minute into the stream for 30 sec-
onds, call play( ) as follows:
in_ns = new NetStream(nc);
in_ns.play("announcements", 60, 30);
If the length parameter is -1 or omitted, the stream plays until it ends. Note that, by
definition, live streams always start playing at the current time; only recorded
streams can be started at some offset. But the length of time to play a stream can be
limited even for live streams by specifying a time limit with the
length parameter.
Creating playlists
By default, invoking play( ) overrides any previous play( ) command for that Net-
Stream object, closing the previous stream immediately and playing the new stream.
However, you can create a playlist in which the server treats a sequence of recorded
streams as a continuous stream; the server provides seamless buffering so that there
are no interruptions when the source stream changes.
To add a stream to a playlist, pass
false as the fourth, optional parameter
(
flushPlaylists) when invoking play( ). This tells FlashCom not to close the previ-
ous stream. Instead, the stream is queued and buffered to play after the streams
already in the playlist. Here is a short example. Note that if
flushPlaylists is speci-
fied as
true or omitted, as shown in the first play( ) invocation, FlashCom reinitial-
izes the playlist:
in_ns = new NetStream(nc);
in_ns.play("announcements", 60, 30);
in_ns.play("live_Camera_1", -1, 15, false);
in_ns.play("live_Camera_2", -1, 15, false);
in_ns.play("prod_trailer", 0, -1, false);
The preceding code creates a playlist that plays the following sequence:
1. 30 seconds of the recorded stream named announcements, starting 60 seconds
into the stream
2. 15 seconds of the live_Camera_1 stream
3. 15 seconds of the live_Camera_2 stream
4. The entire recorded prod_trailer stream
The
flushPlaylists parameter can also be used to control how ActionScript data is
streamed. See the “Stream logs” section later in this chapter.

Get Programming Flash Communication Server 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.