[ Team LiB ] |
Recipe 14.9 Recording and Publishing Video and Audio14.9.1 ProblemYou want to record video and/or audio from a Flash movie and publish it to a FlashCom server. 14.9.2 SolutionCreate 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. 14.9.3 DiscussionTo use a net stream object to record and publish video and/or audio to a FlashCom server, follow these steps:
Even if your FlashCom application permits multiple people to record to a single stream, only one user at a time can record to that stream. Additionally, if a recorded stream is being played by a subscribing client, FlashCom locks the stream, preventing you from recording to it. In both of these scenarios, you can catch these errors with an onStatus( ) method. The net stream's onStatus( ) method is invoked whenever there is a status update related to the stream. Flash passes an info object parameter containing information about the status update to the onStatus( ) handler. When another user is recording to a stream, the code property of the info object has the value "NetStream.Publish.BadName"; when the stream is being played, the code property has the value "NetStream.Record.NoAccess". Here is an example with an onStatus( ) handler that detects these error codes: myConnection = new NetConnection( ); myConnection.connect("rtmp:/myApplication/"); publishRecorded_ns = new NetStream(myConnection); publishRecorded_ns.onStatus = function (infoObj) { if (infoObj.code == "NetStream.Publish.BadName") { trace("Someone is already recording to this stream"); } else if (infoObj.code == "NetStream.Record.NoAccess") { trace("Someone is playing this stream"); } else { trace("Stream accessed successfully."); } }; myMic_mic = Microphone.get( ); myCam_cam = Camera.get( ); publishRecorded_ns.attachAudio(myMic_mic); publishRecorded_ns.attachVideo(myCam_cam); publishRecorded_ns.publish("myFirstStream", "record"); 14.9.4 See AlsoRecipe 14.10. For more information on client-side NetStream info object codes, see http://download.macromedia.com/pub/flashcom/documentation/FlashCom_CS_ASD.pdf. |
[ Team LiB ] |