flash actionscript 3.0 publish h264 stream

来源:互联网 发布:淘宝上的打折邮票真假 编辑:程序博客网 时间:2024/05/13 22:58

NetStream.publish捕捉摄像头的图像,并编码后发送到FMS服务器。flash 11终于支持发布h264的流。因为推送h264的流,需要flash player能编码h264格式视频,在flash player 11加入了h264编码器。

官方参考:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/H264VideoStreamSettings.html

编写推送h164的as程序必须要较高版本的sdk,之前使用的flex sdk 4.1的flash player版本是10.0,不能用来编写这个程序。

下载flex sdk:

http://www.adobe.com/devnet/flex/flex-sdk-download.html


h264和h263对比图(同样的码率和分辨率):



as3.0代码:

[javascript] view plaincopyprint?
  1. package  
  2. {  
  3.     import fl.controls.Button;  
  4.     import fl.controls.CheckBox;  
  5.     import fl.controls.ComboBox;  
  6.     import fl.controls.Label;  
  7.     import fl.controls.TextInput;  
  8.       
  9.     import flash.display.Sprite;  
  10.     import flash.display.StageAlign;  
  11.     import flash.display.StageScaleMode;  
  12.     import flash.events.Event;  
  13.     import flash.events.MouseEvent;  
  14.     import flash.events.NetStatusEvent;  
  15.     import flash.media.Camera;  
  16.     import flash.media.H264Profile;  
  17.     import flash.media.H264VideoStreamSettings;  
  18.     import flash.media.Microphone;  
  19.     import flash.media.Video;  
  20.     import flash.net.NetConnection;  
  21.     import flash.net.NetStream;  
  22.       
  23.     public class H264Publisher extends Sprite  
  24.     {     
  25.         public function H264Publisher()  
  26.         {  
  27.             if(this.stage == null){  
  28.                 this.addEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage);  
  29.             }  
  30.             else{  
  31.                 this.onAddedToStage(null);  
  32.             }  
  33.         }  
  34.           
  35.         private function onAddedToStage(evt:Event):void{  
  36.             this.stage.align = StageAlign.TOP_LEFT;  
  37.             this.stage.scaleMode = StageScaleMode.NO_SCALE;  
  38.               
  39.             var urlPanel:Sprite = new Sprite();  
  40.             this.addUrlPanel(urlPanel, onMouseClickStartPublish, onMouseClickStopPublish);  
  41.               
  42.             var cameraPanel:Sprite = new Sprite();  
  43.             this.addCameraPanel(cameraPanel);  
  44.               
  45.             var encodingPanel:Sprite = new Sprite();  
  46.             this.addEncodingPanel(encodingPanel);  
  47.               
  48.             urlPanel.x = 10;  
  49.             urlPanel.y = 10;  
  50.               
  51.             cameraPanel.x = urlPanel.x;  
  52.             cameraPanel.y = urlPanel.y + 30;  
  53.               
  54.             encodingPanel.x = cameraPanel.x;  
  55.             encodingPanel.y = cameraPanel.y + 30;  
  56.               
  57.             video = new Video();  
  58.             video.x = encodingPanel.x;  
  59.             video.y = encodingPanel.y + 30;  
  60.               
  61.             this.addChild(urlPanel);  
  62.             this.addChild(cameraPanel);  
  63.             this.addChild(encodingPanel);  
  64.             this.addChild(video);  
  65.         }  
  66.           
  67.         private var fmsUrl:String;  
  68.         private var fmsStream:String;  
  69.         private function discoveryFmsUrl():void{  
  70.             var url:String = txtUrl.text;  
  71.               
  72.             if(url.toLowerCase().indexOf("rtmp://") < 0){  
  73.                 trace("[error] the url must start with rtmp://""error");  
  74.                 return;  
  75.             }  
  76.               
  77.             // remove the start rtmp://  
  78.             url = url.substr(url.toLowerCase().indexOf("rtmp://") + "rtmp://".length);  
  79.               
  80.             var server:String = url.substr(0, url.indexOf("/"));  
  81.             url = url.substr(url.indexOf("/") + 1);  
  82.               
  83.             var port:String = "1935";  
  84.             if(server.indexOf(":") >= 0){  
  85.                 port = server.substr(server.indexOf(":")+1);  
  86.                 server = server.substr(0, server.indexOf(":"));  
  87.             }  
  88.               
  89.             var appIndex:int = -1;  
  90.             for(var i:int = 0; i < this.cbAppLevel.selectedIndex + 1; i++){  
  91.                 if(url.indexOf("/", appIndex + 1) < 0){  
  92.                     break;  
  93.                 }  
  94.                   
  95.                 appIndex = url.indexOf("/", appIndex + 1);  
  96.             }  
  97.             var app:String = url.substr(0, appIndex);  
  98.             var stream:String = url.substr(appIndex + 1);  
  99.               
  100.             // if user input ip address, set the server; otherwise, set the vhost.  
  101.             var serverIsIPAddress:Boolean = true;  
  102.             var serverItems:Array = server.split(".");  
  103.             for(i = 0; i < serverItems.length; i++){  
  104.                 if(isNaN(Number(serverItems[i]))){  
  105.                     serverIsIPAddress = false;  
  106.                 }  
  107.             }  
  108.               
  109.             fmsUrl = "rtmp://" + server + ":" + port + "/" + app;  
  110.             fmsStream = stream;  
  111.         }  
  112.           
  113.         private function buildEncodingParameters(publishStream:NetStream, c:Camera, m:Microphone):void{  
  114.             var x264profile:String = (this.cbX264Profile.selectedLabel == "Main") ? H264Profile.MAIN : H264Profile.BASELINE;  
  115.             var x264level:String = this.cbX264Level.selectedLabel;  
  116.             var x264KeyFrameInterval:int = int(this.cbX264KeyFrameInterval.selectedIndex + 1);  
  117.             var cameraWidth:int = int(this.cbCameraSize.selectedLabel.substr(0, this.cbCameraSize.selectedLabel.indexOf("x")));  
  118.             var cameraHeight:int = int(this.cbCameraSize.selectedLabel.substr(this.cbCameraSize.selectedLabel.indexOf("x") + 1));;  
  119.             var cameraFps:Number = Number(this.cbCameraFps.selectedLabel);  
  120.             var cameraBitrate:int = int(this.cbCameraBitrate.selectedLabel);  
  121.             var cameraQuality:int = 85;  
  122.             var microEncodeQuality:int = 8;  
  123.             var microRate:int = 22; // 22 === 22050 Hz  
  124.               
  125.             trace("[Publish] h.264(x264) encoding parameters: "   
  126.                 + "profile=" + x264profile   
  127.                 + ", level=" + x264level  
  128.                 + ", keyFrameInterval(gop)=" + x264KeyFrameInterval  
  129.                 + "; video(camera) width=" + cameraWidth  
  130.                 + ", height=" + cameraHeight  
  131.                 + ", fps=" + cameraFps  
  132.                 + ", bitrate=" + cameraBitrate  
  133.                 + ", quality=" + cameraQuality  
  134.                 + "; audio(microphone) encodeQuality=" + microEncodeQuality  
  135.                 + ", rate=" + microRate + "(22050Hz)"  
  136.             );  
  137.               
  138.             var h264Settings:H264VideoStreamSettings = new H264VideoStreamSettings();  
  139.             // we MUST set its values first, then set the NetStream.videoStreamSettings, or it will keep the origin values.  
  140.             h264Settings.setProfileLevel(x264profile, x264level);   
  141.             publishStream.videoStreamSettings = h264Settings;  
  142.             // the setKeyFrameInterval/setMode/setQuality use the camera settings.  
  143.             // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/VideoStreamSettings.html  
  144.             // Note This feature will be supported in future releases of Flash Player and AIR, for now, Camera parameters are used.  
  145.             /*h264Settings.setKeyFrameInterval(4); 
  146.             h264Settings.setMode(800, 600, 15); 
  147.             h264Settings.setQuality(500, 0);*/  
  148.               
  149.             // set the camera and microphone.  
  150.               
  151.             // setKeyFrameInterval(keyFrameInterval:int):void  
  152.             //  keyFrameInterval:int — A value that specifies which video frames are transmitted in full (as keyframes) instead of being   
  153.             //      interpolated by the video compression algorithm. A value of 1 means that every frame is a keyframe, a value of 3 means   
  154.             //      that every third frame is a keyframe, and so on. Acceptable values are 1 through 48.  
  155.             c.setKeyFrameInterval(x264KeyFrameInterval);  
  156.               
  157.             // setMode(width:int, height:int, fps:Number, favorArea:Boolean = true):void  
  158.             //  width:int — The requested capture width, in pixels. The default value is 160.  
  159.             //  height:int — The requested capture height, in pixels. The default value is 120.  
  160.             //  fps:Number — The requested rate at which the camera should capture data, in frames per second. The default value is 15.  
  161.             c.setMode(cameraWidth, cameraHeight, cameraFps);  
  162.               
  163.             // setQuality(bandwidth:int, quality:int):void  
  164.             //  bandwidth:int — Specifies the maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second.   
  165.             //      To specify that the video can use as much bandwidth as needed to maintain the value of quality, pass 0 for bandwidth.   
  166.             //      The default value is 16384.  
  167.             //  quality:int — An integer that specifies the required level of picture quality, as determined by the amount of compression   
  168.             //      being applied to each video frame. Acceptable values range from 1 (lowest quality, maximum compression) to 100   
  169.             //      (highest quality, no compression). To specify that picture quality can vary as needed to avoid exceeding bandwidth,   
  170.             //      pass 0 for quality.   
  171.             //  winlin:   
  172.             //      bandwidth is in bps not kbps. 500*1000 = 500kbps.  
  173.             //      quality=1 is lowest quality, 100 is highest quality.  
  174.             c.setQuality(cameraBitrate * 1000, cameraQuality);  
  175.               
  176.             // if no microphone, donot set the params.  
  177.             if(m == null){  
  178.                 return;  
  179.             }  
  180.               
  181.             // The encoded speech quality when using the Speex codec. Possible values are from 0 to 10. The default value is 6. Higher numbers   
  182.             // represent higher quality but require more bandwidth, as shown in the following table. The bit rate values that are listed represent   
  183.             // net bit rates and do not include packetization overhead.  
  184.             m.encodeQuality = microEncodeQuality;  
  185.               
  186.             // The rate at which the microphone is capturing sound, in kHz. Acceptable values are 5, 8, 11, 22, and 44. The default value is 8 kHz   
  187.             // if your sound capture device supports this value. Otherwise, the default value is the next available capture level above 8 kHz that   
  188.             // your sound capture device supports, usually 11 kHz.  
  189.             m.rate = microRate;  
  190.         }  
  191.           
  192.         private var publishStream:NetStream;  
  193.         private var publishConnection:NetConnection;  
  194.         private function onMouseClickStartPublish(evt:MouseEvent):void{  
  195.             // if published, donothing  
  196.             if(publishStream != null){  
  197.                 return;  
  198.             }  
  199.               
  200.             this.btnStartPublish.enabled = false;  
  201.             this.btnStopPublish.enabled = true;  
  202.               
  203.             this.discoveryFmsUrl();  
  204.               
  205.             publishConnection = new NetConnection();  
  206.             var conn:NetConnection = publishConnection;  
  207.               
  208.             conn.client = {};  
  209.             conn.client.onBWDone = function():void{};  
  210.               
  211.             conn.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void{  
  212.                 trace("[Publish][connection] code:" + evt.info.code);  
  213.                   
  214.                 switch(evt.info.code){  
  215.                     case "NetConnection.Connect.Success":  
  216.                         publishStream = new NetStream(conn);  
  217.                         // microphone and camera  
  218.                         var m:Microphone = Microphone.getMicrophone(cbMicrophone.selectedIndex);  
  219.                         // Remark: the name is the index!  
  220.                         var c:Camera = Camera.getCamera(String(cbCamera.selectedIndex));  
  221.                         if(c == null){  
  222.                             trace("[Publish][error] failed to open camera(name=" + String(cbCamera.selectedIndex) + "): " + cbCamera.selectedLabel, "error");  
  223.                             cleanupPublishedStream();  
  224.                             break;  
  225.                         }  
  226.                         else if(c.muted){  
  227.                             trace("[Publish][error] open camera(name=" + String(cbCamera.selectedIndex) + ") failed, it's muted: " + cbCamera.selectedLabel, "error");  
  228.                             cleanupPublishedStream();  
  229.                             break;  
  230.                         }  
  231.                           
  232.                         buildEncodingParameters(publishStream, c, m);  
  233.                           
  234.                         publishStream.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void{  
  235.                             trace("[Publish][NetStreamStatus]" + evt.info.code);  
  236.                               
  237.                             switch(evt.info.code){  
  238.                                 case "NetStream.Publish.Start":  
  239.                                     var h264:H264VideoStreamSettings = publishStream.videoStreamSettings as H264VideoStreamSettings;  
  240.                                     trace("[Publish] video codec: " + h264.codec   
  241.                                         + ", profile=" + h264.profile  
  242.                                         + ", level=" + h264.level  
  243.                                         + ", quality=" + h264.quality  
  244.                                         + ", fps=" + h264.fps  
  245.                                         + ", gop=" + h264.keyFrameInterval  
  246.                                         + ", bandwidth=" + h264.bandwidth  
  247.                                         + ", size=" + h264.width + "x" + h264.height);  
  248.                                     break;  
  249.                                 case "NetStream.Publish.BadName":  
  250.                                     cleanupPublishedStream();  
  251.                                     break;  
  252.                             }  
  253.                         });  
  254.                         publishStream.publish(fmsStream);  
  255.                           
  256.                         // attach video and audio.  
  257.                         trace("[Publish][debug] start publish, using camera(name=" + String(cbCamera.selectedIndex) + "): " + c.name);  
  258.                         publishStream.attachCamera(c);  
  259.                         if(m != null && !m.muted){  
  260.                             trace("[Publish][debug] start publish, using microphone(name=" + String(cbMicrophone.selectedIndex) + "): " + m.name);  
  261.                             publishStream.attachAudio(m);  
  262.                         }  
  263.                         restartPlayback();  
  264.                         break;  
  265.                     case "NetConnection.Connect.Rejected":  
  266.                     case "NetConnection.Connect.Failed":  
  267.                         cleanupPublishedStream();  
  268.                         break;  
  269.                 }  
  270.             });  
  271.               
  272.             conn.connect(fmsUrl);  
  273.         }  
  274.         private function cleanupPublishedStream():void{  
  275.             this.btnStartPublish.enabled = true;  
  276.             this.btnStopPublish.enabled = false;  
  277.             if(this.publishStream != null){  
  278.                 this.publishStream.close();  
  279.             }  
  280.             if(this.publishConnection != null){  
  281.                 this.publishConnection.close();  
  282.             }  
  283.             this.publishStream = null;  
  284.         }  
  285.           
  286.         public var stream:NetStream;  
  287.         private var conn:NetConnection;  
  288.         private var video:Video;  
  289.         private function restartPlayback():void{  
  290.             // stream is playing, resume it.  
  291.             if(this.stream != null){  
  292.                 this.stream.close();  
  293.             }  
  294.               
  295.             conn = new NetConnection();  
  296.               
  297.             conn.client = {};  
  298.             conn.client.onBWDone = function():void{};  
  299.             conn.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void{  
  300.                 trace("[connection] code:" + evt.info.code + " desc:" + evt.info.description);  
  301.                   
  302.                 switch(evt.info.code){  
  303.                     case "NetConnection.Connect.Success":  
  304.                         stream = new NetStream(conn);  
  305.                         video.attachNetStream(stream);  
  306.                           
  307.                         //stream.bufferTime = 3;  
  308.                         stream.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void{  
  309.                             trace("[NetStreamStatus]" + evt.info.code + " desc:" + evt.info.description);  
  310.                         });  
  311.                         stream.client = {};  
  312.                         stream.client.onMetaData = function onMetadata(metadata:Object):void{  
  313.                             var o:Object = {};  
  314.                             for(var key:String in metadata){  
  315.                                 o[key] = metadata[key];  
  316.                                 trace("[metadata] " + "key=" + key + ", value=" + o[key]);  
  317.                             }  
  318.                               
  319.                             if(metadata.width == undefined){  
  320.                                 metadata.width = 10;  
  321.                                 trace("[warning] metadata.width is undefied, set to 10");  
  322.                             }  
  323.                             if(metadata.height == undefined){  
  324.                                 metadata.height = 10;  
  325.                                 trace("[warning] metadata.height is undefied, set to 10");  
  326.                             }  
  327.                               
  328.                             video.width = metadata.width;  
  329.                             video.height = metadata.height;  
  330.                         };  
  331.                           
  332.                         if(!cbIsLive.selected){  
  333.                             stream.play(fmsStream, 0);  
  334.                         }  
  335.                         else{  
  336.                             stream.play(fmsStream);  
  337.                         }  
  338.                         break;  
  339.                     case "NetConnection.Connect.Rejected":  
  340.                     case "NetConnection.Connect.Failed":  
  341.                         stream.close();  
  342.                         stream = null;  
  343.                         break;  
  344.                 }  
  345.             });  
  346.             conn.connect(fmsUrl);  
  347.         }  
  348.           
  349.         private function onMouseClickStopPublish(evt:MouseEvent):void{  
  350.             this.cleanupPublishedStream();  
  351.         }  
  352.           
  353.         private var txtUrl:TextInput;  
  354.         private var btnStartPublish:Button;  
  355.         private var btnStopPublish:Button;  
  356.         private var cbAppLevel:ComboBox;  
  357.         private var cbIsLive:CheckBox;  
  358.         private function addUrlPanel(  
  359.             panel:Sprite,   
  360.             onMouseClickStartPublish:Function, onMouseClickStopPublish:Function  
  361.         ):void{  
  362.             var lblUrl:Label = new Label();  
  363.             lblUrl.text = "RTMP Url:";  
  364.             lblUrl.width = 50;  
  365.             panel.addChild(lblUrl);  
  366.               
  367.             txtUrl = new TextInput();  
  368.             txtUrl.width = 380;  
  369.             txtUrl.x = lblUrl.x + lblUrl.width + 3;  
  370.             panel.addChild(txtUrl);  
  371.               
  372.             cbIsLive = new CheckBox();  
  373.             cbIsLive.selected = true;  
  374.             cbIsLive.label = "Live";  
  375.             cbIsLive.width = 53;  
  376.             cbIsLive.x = txtUrl.x + txtUrl.width + 0;  
  377.             panel.addChild(cbIsLive);  
  378.               
  379.             cbAppLevel = new ComboBox();  
  380.             cbAppLevel.addItem({label: "1级App"});  
  381.             cbAppLevel.addItem({label: "2级App"});  
  382.             cbAppLevel.addItem({label: "3级App"});  
  383.             cbAppLevel.addItem({label: "4级App"});  
  384.             cbAppLevel.width = 70;  
  385.             cbAppLevel.x = cbIsLive.x + cbIsLive.width + 0;  
  386.             panel.addChild(cbAppLevel);  
  387.               
  388.             btnStartPublish = new Button();  
  389.             btnStartPublish.label = "发布流";  
  390.             btnStartPublish.width = 60;  
  391.             btnStartPublish.x = cbAppLevel.x + cbAppLevel.width + 3;  
  392.             btnStartPublish.addEventListener(MouseEvent.CLICK, onMouseClickStartPublish);  
  393.             panel.addChild(btnStartPublish);  
  394.               
  395.             btnStopPublish = new Button();  
  396.             btnStopPublish.label = "停止发布";  
  397.             btnStopPublish.width = 60;  
  398.             btnStopPublish.enabled = false;  
  399.             btnStopPublish.x = btnStartPublish.x + btnStartPublish.width + 3;  
  400.             btnStopPublish.addEventListener(MouseEvent.CLICK, onMouseClickStopPublish);  
  401.             panel.addChild(btnStopPublish);  
  402.         }  
  403.           
  404.         private var cbX264Profile:ComboBox;  
  405.         private var cbX264Level:ComboBox;  
  406.         private var cbX264KeyFrameInterval:ComboBox;  
  407.         private var cbCameraSize:ComboBox;  
  408.         private var cbCameraFps:ComboBox;  
  409.         private var cbCameraBitrate:ComboBox;  
  410.         private function addEncodingPanel(  
  411.             panel:Sprite  
  412.         ):void{  
  413.             var lblX264Profile:Label = new Label();  
  414.             lblX264Profile.text = "Profile:";  
  415.             lblX264Profile.width = 38;  
  416.             lblX264Profile.y = 2;  
  417.             panel.addChild(lblX264Profile);  
  418.               
  419.             cbX264Profile = new ComboBox();  
  420.             cbX264Profile.width = 72;  
  421.             cbX264Profile.x = lblX264Profile.x + lblX264Profile.width + 0;  
  422.             panel.addChild(cbX264Profile);  
  423.             cbX264Profile.addItem({label:"Baseline"});  
  424.             cbX264Profile.addItem({label:"Main"});  
  425.               
  426.             var lblX264Level:Label = new Label();  
  427.             lblX264Level.text = "Level:";  
  428.             lblX264Level.width = 32;  
  429.             lblX264Level.y = 2;  
  430.             lblX264Level.x = cbX264Profile.x + cbX264Profile.width + 1;  
  431.             panel.addChild(lblX264Level);  
  432.               
  433.             cbX264Level = new ComboBox();  
  434.             cbX264Level.width = 45;  
  435.             cbX264Level.x = lblX264Level.x + lblX264Level.width + 1;  
  436.             panel.addChild(cbX264Level);  
  437.             var x264Levels:Array = ["1""1b""1.1""1.2""1.3""2""2.1""2.2""3""3.1""3.2""4""4.1""4.2""5""5.1"];  
  438.             for(var i:int = 0; i < x264Levels.length; i++){  
  439.                 cbX264Level.addItem({label:x264Levels[i]});  
  440.             }  
  441.             cbX264Level.selectedIndex = 8;  
  442.               
  443.             var lblX264KeyFrameInterval:Label = new Label();  
  444.             lblX264KeyFrameInterval.text = "GOP:";  
  445.             lblX264KeyFrameInterval.width = 29;  
  446.             lblX264KeyFrameInterval.y = 2;  
  447.             lblX264KeyFrameInterval.x = cbX264Level.x + cbX264Level.width + 1;  
  448.             panel.addChild(lblX264KeyFrameInterval);  
  449.               
  450.             cbX264KeyFrameInterval = new ComboBox();  
  451.             cbX264KeyFrameInterval.width = 87;  
  452.             cbX264KeyFrameInterval.x = lblX264KeyFrameInterval.x + lblX264KeyFrameInterval.width + 1;  
  453.             panel.addChild(cbX264KeyFrameInterval);  
  454.             for(i = 0; i < 48; i++){  
  455.                 cbX264KeyFrameInterval.addItem({label:String(i + 1) + " seconds"});  
  456.             }  
  457.             cbX264KeyFrameInterval.selectedIndex = 3;  
  458.               
  459.             var lblCameraSize:Label = new Label();  
  460.             lblCameraSize.text = "Size:";  
  461.             lblCameraSize.width = 30;  
  462.             lblCameraSize.y = 2;  
  463.             lblCameraSize.x = cbX264KeyFrameInterval.x + cbX264KeyFrameInterval.width + 1;  
  464.             panel.addChild(lblCameraSize);  
  465.               
  466.             cbCameraSize = new ComboBox();  
  467.             cbCameraSize.width = 82;  
  468.             cbCameraSize.x = lblCameraSize.x + lblCameraSize.width + 1;  
  469.             panel.addChild(cbCameraSize);  
  470.             var sizes:Array = ["176x144""320x240""352x240""352x288""640x480""720x480""720x576""800x600""1024x768""1280x720""1360x768""1920x1080"];  
  471.             for(i = 0; i < sizes.length; i++){  
  472.                 cbCameraSize.addItem({label:sizes[i]});  
  473.             }  
  474.             cbCameraSize.selectedIndex = 1;  
  475.               
  476.             var lblCameraFps:Label = new Label();  
  477.             lblCameraFps.text = "FPS:";  
  478.             lblCameraFps.width = 28;  
  479.             lblCameraFps.y = 2;  
  480.             lblCameraFps.x = cbCameraSize.x + cbCameraSize.width + 1;  
  481.             panel.addChild(lblCameraFps);  
  482.               
  483.             cbCameraFps = new ComboBox();  
  484.             cbCameraFps.width = 58;  
  485.             cbCameraFps.x = lblCameraFps.x + lblCameraFps.width + 1;  
  486.             panel.addChild(cbCameraFps);  
  487.             var fpses:Array = ["1.00""4.00""5.00""6.00""8.00""10.00""12.00""14.98""15.00""20.00""24.00""25.00""29.97""30.00""59.94""60.00"];  
  488.             for(i = 0; i < fpses.length; i++){  
  489.                 cbCameraFps.addItem({label:fpses[i]});  
  490.             }  
  491.             cbCameraFps.selectedIndex = 8;  
  492.               
  493.             var lblCameraBitrate:Label = new Label();  
  494.             lblCameraBitrate.text = "Bitrate:";  
  495.             lblCameraBitrate.width = 40;  
  496.             lblCameraBitrate.y = 2;  
  497.             lblCameraBitrate.x = cbCameraFps.x + cbCameraFps.width + 1;  
  498.             panel.addChild(lblCameraBitrate);  
  499.               
  500.             cbCameraBitrate = new ComboBox();  
  501.             cbCameraBitrate.width = 58;  
  502.             cbCameraBitrate.x = lblCameraBitrate.x + lblCameraBitrate.width + 1;  
  503.             panel.addChild(cbCameraBitrate);  
  504.             var bitrates:Array = ["10""50""100""200""350""500""650""800""950""1000""1200""1500""1800""2000""2500""20000"];  
  505.             for(i = 0; i < bitrates.length; i++){  
  506.                 cbCameraBitrate.addItem({label:bitrates[i]});  
  507.             }  
  508.             cbCameraBitrate.selectedIndex = 3;  
  509.         }  
  510.           
  511.         private var cbCamera:ComboBox;  
  512.         private var cbMicrophone:ComboBox;  
  513.         private function addCameraPanel(  
  514.             panel:Sprite  
  515.         ):void{  
  516.             // camera   
  517.             var lblCamera:Label = new Label();  
  518.             lblCamera.text = "Available Cameras:";  
  519.             lblCamera.width = 100;  
  520.             panel.addChild(lblCamera);  
  521.               
  522.             cbCamera = new ComboBox();  
  523.             cbCamera.width = 160;  
  524.             cbCamera.x = lblCamera.x + lblCamera.width + 3;  
  525.             panel.addChild(cbCamera);  
  526.               
  527.             var cameras:Array = Camera.names;  
  528.             for(var i:int = 0; i < cameras.length; i++){  
  529.                 cbCamera.addItem({label:cameras[i]});  
  530.             }  
  531.               
  532.             // microphone   
  533.             var lblMicrophone:Label = new Label();  
  534.             lblMicrophone.text = "Available Microphones:";  
  535.             lblMicrophone.width = 120;  
  536.             lblMicrophone.x = cbCamera.x + cbCamera.width + 10;  
  537.             panel.addChild(lblMicrophone);  
  538.               
  539.             cbMicrophone = new ComboBox();  
  540.             cbMicrophone.width = 180;  
  541.             cbMicrophone.x = lblMicrophone.x + lblMicrophone.width + 3;  
  542.             panel.addChild(cbMicrophone);  
  543.               
  544.             var microphones:Array = Microphone.names;  
  545.             for(i = 0; i < microphones.length; i++){  
  546.                 cbMicrophone.addItem({label:microphones[i]});  
  547.             }  
  548.         }  
  549.     }  
  550. }  

其中用到了FlashCS5的控件,可以将c:\Program Files (x86)\Adobe\Adobe Flash CS5\Common\Configuration\Components\User Interface.fla打开后导出swc,然后在actionscript3项目中引用这个swc就可以了。
原创粉丝点击