Red5-based online video recording instance

Source: Internet
Author: User
Tags flv file

Under pressure, I studied red5 and as3 last night and found it quite interesting.
Red5 and fms are both good things, and they find learning things very fast under pressure.

 

The code is as follows: Copy code

// 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 );

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.