Flash/flex Study Notes (12): How to live video in real time in the FMS 3.5

Source: Internet
Author: User

Hardware condition: One Camera + one FMS Server

Principle: The camera collects video sources in real time and then pushes them to the FMS server. Other customers obtain video streams from FMS.

Two flas are required. One is used to push the video source (that is, the sender) to the SSP server, and the other is used to obtain and play the video (that is, the receiver) from the FMS server)

Server. fla keyCode:

VaR cam: Camera; var VOD: Video; var intervalid: uint; var intelvaltimes: uint = 0; var isworked = false; var NC: netconnection; var ns: netstream; btnpublish. addeventlistener (mouseevent. click, btnpublishclick); lblmsg. TEXT = "connect to the camera, \ n click the button below" // function camactivityhandler (E: activityevent) {trace (E); If (! Isworked) {intervalid = setinterval (checkcallback, 100) ;}} function checkcallback (): void {intelvaltimes + = 1; trace (intelvaltimes); If (cam. currentfps> 0) {lblmsg. TEXT = "the camera is working properly! "; Isworked = true; clearinterval (intervalid); NS. publish ("mycamera", "live"); // simultaneously play VOD = new video (); Vod. attachcamera (CAM); Vod. height = cam. height; Vod. width = cam. width; Vod. X = 45; Vod. y = 15; addchild (VOD);} else {If (intelvaltimes> = 10) {// if the image remains unchanged for 2 seconds, "The device is unavailable (in use)" lblmsg. TEXT = "unable to use the device (may be occupied)"; clearinterval (intervalid );}}} // function statushandler (E: statusevent) {trace (E); If (E. Code = "camera. muted") {lblmsg. Text = "you are not allowed to use the camera! ";} Else if (E. code = "camera. unmuted ") {lblmsg. TEXT = "getting the camera video... ";}} // click the push button to click event function btnpublishclick (E: mouseevent) {NC = new netconnection (); NC. addeventlistener (netstatusevent. net_status, netstatushandler); NC. connect ("rtmp: // SSP Server IP Address/camlive");} // connection status processing code function netstatushandler (Event: netstatusevent): void {trace (event.info. code); If (event.info. code = "netconnection. connect. success ") {cam = came RA. getcamera (); If (CAM = NULL) {This. lblmsg. Text = "no camera is installed! "; Return;} cam. addeventlistener (statusevent. status, statushandler); cam. addeventlistener (activityevent. activity, camactivityhandler); NS = new netstream (NC); NS. attachcamera (CAM );}}

 

Client. fla key code:

 
VaR NC: netconnection; var ns: netstream; var VOD: Video; btnreceive. addeventlistener (mouseevent. click, function () {NC = new netconnection (); NC. addeventlistener (netstatusevent. net_status, netstatushandler); NC. connect ("rtmp: // SSP Server IP Address/camlive");}) // connection status processing code function netstatushandler (Event: netstatusevent): void {trace (event.info. code); If (event.info. code = "netconnection. connect. success ") {lblmsg. TEXT = "retrieving video... "NS = new netstream (NC); NS. addeventlistener (netstatusevent. net_status, nsnetstatushandler); NS. play ("mycamera"); VOD = new video (); Vod. X = 45; Vod. y = 15; Vod. height = 120; Vod. width = 160; Vod. attachnetstream (NS); addchild (VOD) ;}} function nsnetstatushandler (E: netstatusevent) {trace (e.info. code );}

Online demonstration:

Push end
Acceptor

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.