Client-Side Communication ActionScript > NetStream (object) |
![]() ![]() ![]() |
NetStream (object)
The NetStream object opens a one-way streaming connection between the Flash Player and the Flash Communication Server through a connection made available by a NetConnection object. A NetStream object is like a channel inside a NetConnection object; this channel can either publish audio and/or video data, using NetStream.publish
, or subscribe to a published stream and receive data, using NetStream.play
. You can publish or play live (real-time) data and play previously recorded data.
You can also use NetStream objects to send text messages to all subscribed clients (see NetStream.send
).
The following steps summarize the sequence of actions required for publishing real-time audio and video using Flash Communication Server and the Real-Time Messaging Protocol (RTMP):
1 |
Use |
2 |
Use |
3 |
Use |
4 |
Use |
5 |
Use |
Movies that subscribe to this stream will use the name specified here; that is, they will call the same |
Multiple streams can be open simultaneously over one connection, but each stream either publishes or plays. To publish and play over a single connection, open two streams over the connection, as shown in the following example. This example publishes audio and video data in real time on one stream and plays it back on another stream on the same client, through the same connection.
// These lines begin broadcasting nc = new NetConnection(); // create connection object nc.connect("rtmp://mySvr.myDomain.com/App"); // connect to server ns = new NetStream(nc); // open stream within connection ns.attachAudio(Microphone.get()); // capture audio ns.attachVideo(Camera.get()); // capture video ns.publish("todays_news"); // begin broadcasting // These lines open a stream to play the video portion of the broadcast // inside a Video object named myVideoArea. // The audio is played through the standard output device--you don't // need to issue a separate command to hear the audio. ns2 = new NetStream(nc); // open another stream over the same connection myVideoArea.attachVideo(ns2); // specify where to display video ns2.play("todays_news"); // play uses the same name as publish, above
In the previous example, note that both the publisher and subscriber call an attachVideo
method. The publisher calls NetStream.attachVideo
to connect a video feed to a stream. The subscriber calls Video.attachVideo
to connect a video feed to a Video object on the Stage; the incoming video is displayed inside this object.
Note also that although the publisher calls an attachAudio
method, the subscriber does not. This is because audio sent through a stream is played through the subscriber's standard audio output device by default; the subscriber doesn't have to attach the incoming audio to an object on the Stage. However, you can use MovieClip.attachAudio
to route audio from a NetStream object to a movie clip. If you do this, you can then create a Sound object to control the volume of the sound. For more information, see MovieClip.attachAudio
.
Method Description Publisher method; specifies whether audio should be sent over the stream. Publisher method; starts transmitting video or a snapshot from the specified source. Stops publishing or playing all data on the stream and makes the stream available for another use. Subscriber method; pauses or resumes playback of a stream. Subscriber method; feeds streaming audio, video, and text messages being published on the Flash Communication Server, or a recorded file stored on the server, to the client. Publisher method; sends streaming audio, video, and text messages from the client to the Flash Communication Server, optionally recording the stream during transmission. Subscriber method; specifies whether incoming audio plays on the stream. Subscriber method; specifies whether incoming video will play on the stream, or specifies the frame rate of the video. Subscriber method; seeks to a position in the recorded stream currently playing. Publisher method; broadcasts a message to all subscribing clients. Method; for a publishing stream, this number indicates how long the outgoing buffer can grow before Flash starts dropping frames. For a subscribing stream, this number indicates how long to buffer incoming data before starting to display the stream.
Method summary for the NetStream object
Property (read-only) Description The number of seconds of data currently in the buffer. The number of seconds assigned to the buffer by The number of frames per second being sent or received on the publishing or subscribing stream. The number of seconds of data in a subscribing stream's buffer in live mode. The number of seconds a stream has been playing or publishing.
Property summary for the NetStream object
NetStream.setBufferTime
.
Method Description Invoked every time a status change or error is posted for the NetStream object.
Event handler summary for the NetStream object
![]() ![]() ![]() |