Recipe 14.10 Publishing Live Content

14.10.1 Problem

You want to publish a live stream without recording it.

14.10.2 Solution

Create a net stream, attach the audio and/or video to the stream using attachAudio( ) and/or attachVideo( ), then call the NetStream.publish( ) method and specify "live" as the recording mode.

14.10.3 Discussion

The procedure to publish a live stream is the same as that of publishing a recorded stream (see Recipe 14.9) except that you specify the mode as "live" when you call the publish( ) method. Live streams are not recorded and are available only as they are being published.

Here is an example that publishes a live stream called "livePresentation":

// Establish the net connection.
myConnection = new NetConnection(  );

// Create a net stream using a net connection named myConnection.
publishLive_ns = new NetStream(myConnection);

// Attach the camera and microphone data to the net stream.
publishLive_ns.attachAudio(Microphone.get(  ));
publishLive_ns.attachVideo(Camera.get(  ));

// Publish the stream as live content.
publishLive_ns.publish("livePresentation", "live");

If not specified, the recording mode defaults to "live". Therefore, the last line of the example could also be written as:


14.10.4 See Also

To publish a live stream and archive it for subsequent playback, see Recipe 14.9.

    Part I: Local Recipes
    Part II: Remote Recipes