This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
10
|
Chapter 1: Introducing the Flash Communication Server
NetStream object, in_ns, is created by passing the NetConnection object, nc, from the
preceding example to the NetStream( ) constructor function:
in_ns = new NetStream(nc);
videoArea.attachVideo(in_ns);
in_ns.play("public/Ryerson_High_Speed");
In this case, the video appears in a video object that was placed on the Stage during
authoring and given the instance name
videoArea; the audio within the video stream
is heard automatically. Note that the .flv extension is not included in the stream URI
passed into the play( ) method.
Publishing a stream in a Flash movie is also easy. Here, we create a new NetStream
object,
out_ns, and attach the audio and video streams from the user’s microphone
and camera before publishing the stream using NetStream.publish( ):
out_ns = new NetStream(nc);
out_ns.attachAudio(Microphone.get( ));
out_ns.attachVideo(Camera.get( ));
out_ns.publish(userName); // Name the stream after the user's name.
The Camera class can get a video stream from a web camera or other video source,
and the Microphone class can get an audio stream from a microphone or other
source.
You can create multiple streams (NetStream objects) for a single NetConnection,as
shown in Figure 1-3. Each stream can publish or play a stream to or from the server,
but data within a stream travels in only one direction. If each user must publish a sin-
gle stream, it is easiest to name the stream after his unique username or unique ID
number.
On the server, the Stream class can be used to create playlists of streams and even to
play and publish streams across multiple servers. A playlist defines a sequence of
streams to be played one after the other. The server buffers them so they play seam-
lessly without interruption; when one stream ends, another begins. Chapter 5 covers
the NetStream and Stream classes in depth.
Camera, Microphone, and Video
The Camera and Microphone classes, covered in depth in Chapter 6, provide access
to video and audio sources (typically cameras and microphones) on the client
Figure 1-3. A client publishing a stream and receiving two streams over one NetConnection
Client NetConnection Application instance
out_ns.publish(blesser)
in1_ns.play(peldi)
in2_ns.play(justin)
blesser
peldi
justin

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.