14.9. Recording and Publishing Video and Audio
Problem
You want to record video and/or audio from a Flash movie and publish it to a FlashCom server.
Solution
Create a net stream, attach
the video using attachVideo(
)
, and attach the audio using attachAudio(
)
. Then call the NetStream.publish( )
method and specify “record” or
“append” as the recording mode.
Discussion
To use a net stream object to record and publish video and/or audio to a FlashCom server, follow these steps:
Establish a net connection:
myConnection = new NetConnection( );
Connect to the FlashCom server:
myConnection.connect("rtmp:/myApplication/");
Create the net stream:
publishRecorded_ns = new NetStream(myConnection);
Attach the audio and/or video to the net stream using the
attachAudio( )
and/orattachVideo( )
method:myMic_mic = Microphone.get( ); myCam_cam = Camera.get( ); publishRecorded_ns.attachAudio(myMic_mic); publishRecorded_ns.attachVideo(myCam_cam);
Use
NetStream.publish( )
to record the stream on the server. The first parameter is the name by which the stream should be known by the FlashCom application (when a client wants to subscribe to it, for example). The second parameter is the recording mode. If you specify “record” as the recording mode, any existing stream of the same name (within the FlashCom application) is overwritten. If you specify “append” as the recording mode, the new stream data is appended to any existing stream of the same name (a new stream is created on the server if none exists).publishRecorded_ns.publish("myFirstStream", ...
Get Actionscript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.