NetStream Object


The NetStream object is a one-way streaming connection between the Flash player and the Flash Communication Server. The NetConnection is used with multiple one-way streams either from the Flash player or from the Flash Communication Server. A NetStream can handle video, audio, a combination, or broadcast messages. It can be used to send or receive live or recorded streams. The server can handle the NetStream object with its Stream object.

To enable Code Hints and Code Completion in the Flash MX ActionScript Editor, use the suffix _ns in the name of the NetStream variable.

NetStream Methods

NetStream.attachAudio(source)

Publishes an audio stream to the Flash Communication Server. This method can be used with the .attachVideo method to send synchronized audio and video on one stream.

source The Microphone object name. A value of null stops the microphone source.
NetStream.attachVideo(source null [, snapShotMilliseconds])

Publishes a video stream to the Flash Communication Server. This method can be used with the .attachAudio method to send synchronized audio and video on one stream.

source The Camera object name. A value of null stops the video source.
snapShotMilliseconds The duration between "snapshots." A value of 0 snaps a picture using the camera and sends a static image as the video source. A positive value determines the time duration, in seconds, between repeated snapshots, which is useful for time-lapse photography or security applications.
NetStream.close()

Destroys the stream and all publishing or subscripting activities.

NetStream.pause(pauseResume)

Pauses toggle a subscribed playback stream.

pauseResume A boolean value; true pauses the incoming video stream and false resumes play.
NetStream.play(whatToPlay false [,start [, length [, flushPlaylists]]])

Plays a subscribed (received) stream from the Flash Communication Server. This method starts the feed of video and audio to the targets as determined in attachVideo and attachAudio. Calling NetStream.play() also starts the client listening for broadcast (send) messages sent in the stream.

whatToPlay The name of a live or pre-recorded stream attached to the server. Recorded stream names are accessed without the . flv extension and must exist in the streams/%instance% folder on the server. A value of false here stops the stream.
start The start time, in seconds, to begin a pre-recorded stream. This parameter can also accept two flag values. A value of “2 first looks to play a live stream. If there is no live stream, it looks for a recorded stream. If there is no recorded and no live stream, it opens a subscription stream and waits for a client to publish to it. A value of “1 looks to play a live stream only. If no live stream is found, it opens a subscription stream and waits for a publisher.
length The duration to play a clip, in seconds. A value of “1 plays a live stream until it is unpublished or plays the full recorded stream. A value of 0 plays a snapshot of the first frame from the start point.
FlushPlaylists A Boolean value. True removes any previous play calls and forces the play. False adds the Play command to a local play list.
NetStream.publish(whatToPublish false [, howToPublish])

Starts or stops publishing a stream of audio, video, and broadcast messages to the server.

WhatToPublish The name of the published stream. This name must be unique on the server. Clients will use this name to subscribe to the stream. The server has rights to overwrite the name specified. A value of false will stop publishing.
HowToPublish Flag values to handle stream recording; default value is live. Other values include record and append.
NetStream.receiveAudio(receive)

Toggles the audio subscription of a stream.

Receive A Boolean value; default value of true. When it is set to true, audio is received. A value of false mutes the audio.
NetStream.receiveVideo(receive FPS)

Toggles the video subscription of a stream.

receive A Boolean value; default value of true. When set to true, video is received. False mutes the video.
FPS Changes the value of the frames per second received. The default is the encoded frame rate of the stream.
NetStream.seek(numberOfSeconds)

Plays the movie forward or backward relative to its current play position. This method is only available with recorded streams.

numberOfSeconds The value in seconds to play the movie forward or backward.
NetStream.send(handlerName [,p1, ,pN])

Broadcasts a message or calls a handler (function) defined on the client within the stream instance. This is a one-way broadcast and cannot handle returned objects.

handlerName The name of the function defined within the stream instance on each subscribed client.
NetStream.setBufferTime(numberOfSeconds)

The length of time or memory reserved for an incoming (subscribed) stream before it starts playing. In the case of an outgoing (published) stream, this method allocates the length of time before frames are dropped to compensate for a slower connection.

numberOfSeconds The number of seconds to be buffered before Flash stops sending data (on a publishing stream) or begins displaying data (on a subscribing stream). The default value is 0.

NetStream Properties

NetStream.bufferLength returns the number of seconds currently loaded within the stream buffer.

NetStream.bufferTime returns the number of seconds available to the buffer set by NetStream.setBufferTime .

NetStream.currentFps returns the frame rate, as a value of frames per second, on the publish or the subscription stream.

NetStream.time is the number of seconds a stream has been playing or publishing.

NetStream Events

NetStream.onStatus is invoked when the status of the NetStream changes. This event handles a NetConnection Information object described in Appendix C.Challenges to the Information object allow you to inform your user about the status of a stream or take appropriate actions in your code.



Macromedia Flash Communication Server MX
Macromedia Flash Communication Server MX
ISBN: 0735713332
EAN: 2147483647
Year: 2002
Pages: 200
Authors: Kevin Towes

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net