// Pre-defined statement Import mx. utils. Delegate; // Create a basic network connection object Var nc: NetConnection = new NetConnection (); // Connect to the local Red5 server Nc. connect ("rtmp: // localhost/online "); // Pass the nc that has established a connection with the red5 server to NetStream Var ns: NetStream = new NetStream (nc ); // Obtain information from the camera and microphone Var cam: Camera = Camera. get (); Var mic: Microphone = Microphone. get (); // Initialize the camera and microphone and call the function SetupCameraMic (); // Save the last recorded content and clear it Var lastVideoName: String = ""; // Listen and start recording and stop recording. PlayButton. addEventListener ("click", Delegate. create (this, playClick )); StopButton. addEventListener ("click", Delegate. create (this, stopClick )); // Define the playclick function for starting recording. Function playClick (): Void { // This flv file is saved in the webapps/oflaDemo/streams/folder. // Assign the camera and microphone to ns Ns. attachVideo (cam ); Ns. attachAudio (mic ); // Assign the camera information to the video display window so that we can see the information instantly. VideoContainer. attachVideo (cam ); // The storage name is defined here, and a unique file name is obtained with a random number. LastVideoName = "red5RecordDemo _" + random (getTimer ()); Ns. publish (lastVideoName, "record "); // Lock the start button to make it invalid PlayButton. enabled = false; // Lock the stop button to make it take effect StopButton. enabled = true; } Function stopClick (): Void { // Close the connection between ns and red5 Ns. close (); // Clear the video display window VideoContainer. attachVideo (null ); VideoContainer. clear (); // Lock the start button to make it take effect PlayButton. enabled = true; // Lock the stop button to make it invalid StopButton. enabled = false; // Play the recorded video PlayLastVideo (); } Function playLastVideo (): Void { // Transfer the recorded video information to the screen display window VideoContainer. attachVideo (ns ); // Return to the recorded video clip Ns. play (lastVideoName ); } Function setupCameraMic (): Void { // Start the camera Cam = Camera. get (); // Set the dimension Cam. setMode (320,240, 30 ); // Set the recording quality Cam. setQuality (0, 70 ); // Start the microphone Mic = Microphone. get (); Mic. setRate (44 ); } |