O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.10. Publishing Live Content

Problem

You want to publish a live stream without recording it.

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.

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(  );
myConnection.connect("rtmp:/myApplication/");

// 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:

publishLive_ns.publish("livePresentation");

See Also

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required