NetStream class
77
5.
Use
NetStream.publish(
publishName
:String)
to give this stream a unique name and
send data over the stream to the Flash Media Server, so others can receive it. You can also
record the data as you publish it, so that users can play it back later.
SWF files that subscribe to this stream will use the name specified here; that is, they will
call the same
NetConnection.connect()
method as the publisher, and then call a
NetStream.play(
publishName
:Object)
method. They will also have to call
Video.attachVideo()
to display the video.
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.
var my_nc:NetConnection = new NetConnection(); // Create connection object.
my_nc.connect("rtmp://mySvr.myDomain.com/App"); // Connect to server.
publish_ns:NetStream = new NetStream(my_nc); // Open stream within
connection.
publish_ns.attachAudio(Microphone.get()); // Capture audio.
publish_ns.attachVideo(Camera.get()); // Capture video.
publish_ns.publish("todays_news"); // Begin broadcasting.
/* These lines open a stream to play the video portion of the broadcast
inside a Video object named my_video. The audio is played through the
standard output device--you don’t need to issue a separate command to
hear the audio. */
var play_ns:NetStream = new NetStream(my_nc);
my_video.attachVideo(play_ns); // Specify where to display video.
play_ns.play("todays_news"); // play() uses the same name as publish()
above.
In the previous example, notice 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.
Keep in mind 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()
.
Содержание FLASH MEDIA SERVER 2-CLIENT-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR FLASH MEDIA SERVER...
Страница 1: ...Client Side ActionScript Language Reference for Flash Media Server 2...
Страница 4: ...4 Contents...
Страница 148: ...148 Client Side ActionScript Language Reference...