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