This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Playing Streams in Detail
|
169
When a NetStream object attempts to subscribe to a live stream, its onStatus( ) han-
dler will normally be called twice and receive the
info.code values “NetStream.Play.
Reset” and “NetStream.Play.Start”.
If the live stream is available, it will begin to play without onStatus( ) being called
again. However, the stream may not have started publishing yet, in which case no
data will be received from FlashCom. The subscribing stream will therefore wait
without generating any further calls to onStatus( ). When the stream is finally pub-
lished, the onStatus( ) handler will be called a third time and passed an information
object with a
code property of “NetStream.Play.PublishNotify”.
There is no notification if a live stream is not available the moment an attempt is
made to subscribe to it.
When a NetStream object attempts to connect to a recorded stream without a
start
parameter or with a start parameter of -2, it is not clear to FlashCom whether the
NetStream is attempting to play a live or recorded stream. Consequently, even if the
recorded stream does not exist, the NetStream will behave as though it is attempting
to play a live stream. However, if a
start parameter of 0 or greater is passed into
play( ), the NetStream looks for a recorded stream only. In such a case, if the
recorded file is found, the onStatus( ) handler is called twice with the
code values
“NetStream.Play.Reset” followed by “NetStream.Play.Start”.
If the file is not found and
start is 0 or greater, FlashCom passes an information
object with a
code value of “NetStream.Play.StreamNotFound” to the onStatus( )
handler.
The next few sections describe typical operational sequences and the status events
they generate. Later, under “Putting the User in Control,” we’ll explain how to use
these events to modify the user interface dynamically to help the user monitor and
control various operations.
Playing MP3 Files
FlashCom 1.5 introduced the ability to stream recorded MPEG layer 3 (MP3) com-
pressed audio files. MP3 files can be saved into a subdirectory of an application’s
streams subdirectory in order to make them available for streaming. Once available,
they can be played using a stream URI that begins with the
mp3: prefix. For example,
if an MP3 file is stored in the following file path:
.../applications/radio/streams/_definst_/jazz/track1.mp3
and a NetConnection is established from a Flash movie to the
_definst_ instance of
the radio application, then the following statement subscribes to a stream that plays
the MP3 file:
in_ns.play("mp3:jazz/track1", 0, -1);

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.