Flex getting started instance-online recording of FLV videos with fms3

Source: Internet
Author: User
I used to think that video recording was a very troublesome task. I had to study the FMS during the past two days. I didn't expect it to be so easy to use the FMS and flex. I just studied this dd, some internal mechanisms are not fully understood. If it is not accurate enough or incorrect, you are welcome to make a brick and talk about its principles first: flex uses the rtmp protocol to establish a connection with the SSP, that is, the server. The biggest difference between rtmp and HTTP is that rtmp is a stateful protocol that not only can maintain a connection with the client, in addition, it can monitor the client's behavior and actively interact with it, while HTTP is a stateless protocol. When the client initiates a request and the server completes the response, a session passes Program It's over. in Flex, The netconnection and netstream classes are mainly used. If you have programming experience, you can see what these two guys are doing. I won't say much about it. first look Code Right: In comments: Java code <? XML version = "1.0" encoding = "UTF-8"?> <Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" creationcomplete = "initapp ();"> <mx: SCRIPT> <! [CDATA [import MX. messaging. errors. nochannelavailableerror; private var NC: netconnection; private var ns: netstream; private var rtmpnow: string; private var MSG: Boolean; private var metasnifer: object; private var dur: number; private var cam: Camera; private var mic: microphone; private var vid1: Video; Private function initapp (): void {// initialize a network connection NC = new netconnection (); // Add an event for this connection. This event returns the connection status NC. addeventlistener (netstatusevent. net_status, checkconnect); // This is the connection address. In fact, in the installation directory of your FMS, create a vid2 folder under applications, this folder can be viewed as your project name. // recordings is the folder for storing videos during video recording. rtmpnow = "rtmp: // localhost/vid2/recordings "; // start connecting to NC. connect (rtmpnow); addmedia ();} private function checkconnect (Event: netstatusevent): void {// determine whether the connection is established successfully based on the status information returned by the connection. MSG = (event.info. code = "netconnection. connect. success "); msgerror. TEXT = event.info. code; If (MSG) {// If successful, use some connections to create a stream for future recording and transmission data NS = new netstream (NC); msgerror. TEXT = "establish netstream" ;}} private function startrecord (E: Event): void {If (NS) {msgerror. TEXT = "start record"; // The micphone and camera NS must be loaded when the recording starts. attachaudio (MIC); NS. attachcamera (CAM); // This is the key. Recording starts from here, and input. text is the name of the recorded video file ns. publish (input. text, "record") ;}} private function stop (Event: Event): void {// similar to Java, you must remember to disable Ns for stream-class things. play (false); NS. close (); msgerror. TEXT = "stop";} private function addmedia (): void {// obtain the System camera cam = camera. getcamera (); // set the width, height, and frame cam. setmode (240,180, 24); // sets the video quality cam. setquality (); // obtain the system's microphone MIC = microphone. getmicrophone (); // Let videodisplay load the camera vv. attachcamera (CAM); msgerror. TEXT = "initnize";}]> </MX: SCRIPT> <mx: vbox id = "myvb"> <mx: videodisplay id = "VV" width = "400" Height = "300"/> <mx: button label = "record" id = "BTN" Click = "startrecord (event ); "/> <mx: button label =" play "id =" stopbtn "Click =" Stop (event); "/> <mx: textinput id = "input"/> <mx: textarea id = "msgerror" backgroundcolor = "red"/> </MX: vbox> </MX: Application>

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.