2014-03-05 43 views
1

大家好我正在Flash Builder 4.6中的移動相機應用程序。 我的問題是,我可以讓相機使用網絡攝像頭,但不能使用移動攝像頭進行部署。我正在使用AIR試圖流式傳輸。
這是我打電話給我的按鈕:Flash builder 4.6相機應用程序移動

<?xml version="1.0" encoding="utf-8"?> 
    <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" title="Capture"> 
     <!-- Button event script --> 
     <fx:Script> 
      <![CDATA[ 
       { 
        //Bring in the actionscript 
        import views.CoolVideo; 
        //The button handler 
        private function button1_clickHandler(event:MouseEvent):void 
        { 
         //Calling the actionScript function 
         new CoolVideo(); 
        } 
       } 
      ]]> 
     </fx:Script> 
     <!-- Basic structure of the app page --> 
     <s:VGroup width="100%" height="100%" verticalAlign="middle" horizontalAlign="center"> 
      <!-- Label on the screen --> 
      <s:Label text="Capture page(current)"/> 
      <!-- Button to change between screens --> 
      <s:Button label="Capture" click="button1_clickHandler(event)" styleName="next"/> 
      <s:Button label="Back" click="navigator.pushView(app3HomeView)" styleName="next"/> 
      <!--<s:Image id="img" height="649" y="124" width="460" x="10"/> --> 
     </s:VGroup> 
    </s:View> 

在這裏,我打電話給我的一個按鈕處理button1_clickHandler肚裏的動作動作:

package views 
{ 
    import flash.display.Sprite; 
    import flash.display.Stage; 
    import flash.display.StageAlign; 
    import flash.display.StageScaleMode; 
    import flash.events.MouseEvent; 
    import flash.events.NetStatusEvent; 
    import flash.media.Camera; 
    import flash.media.CameraUI; 
    import flash.media.H264Level; 
    import flash.media.H264Profile; 
    import flash.media.H264VideoStreamSettings; 
    import flash.media.Video; 
    import flash.net.NetConnection; 
    import flash.net.NetStream; 
    import flash.text.TextField; 
    import flash.text.TextFormat; 

    public class CoolVideo extends Sprite 
    { 
     //All the Stuff we need 
     private var metaText:TextField = new TextField(); 
     private var vid_outDescription:TextField = new TextField(); 
     private var vid_inDescription:TextField = new TextField(); 
     private var metaTextTitle:TextField = new TextField(); 

     //the connection will be used to link to server 
     private var nc:NetConnection; 

     //net stream is the data flow 
     private var ns_out:NetStream; 

     //the camera, get camera looks for an available camera returns null if not one available 
     private var cam:Camera = Camera.getCamera(); 

     //this will be the video streamed to the server 
     private var vid_out:Video; 



     //Class constructor 
     public function CoolVideo() 
     { 
      //Call initConnection() 
      initConnection(); 
     } 

     //Called from class constructor, this function establishes a new NetConnection and listens for its status 
     private function initConnection():void 
     { 
      //instantiate netConnection 
      nc = new NetConnection(); 

      //The on status event is where all the streaming will go on 
      nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); 

      //make net Connection to the server 
      nc.connect("rtmp://192.168.200.233/livepkgr/_definst_/"); 

      //Step 7: Tell the NetConnection where the server should invoke callback methods 
      nc.client=this; 

      //Instantiate the vid_out variable 
      vid_out = new Video(); 
     } 

     //It's a best practice to always check for a successful NetConnection 
     protected function onNetStatus(event:NetStatusEvent):void 
     { 
      //Step 8: Trace the value of event.info.code 
      trace(event.info.code); 

      /*Step 9: Check for a successful NetConnection, and if successful 
      call publishCamera()*/ 
      if(event.info.code == "NetConnection.Connect.Success") 
      { 
       publishCamera(); 
      } 
     } 

     //The encoding settings are set on the publishing stream 
     protected function publishCamera():void 
     { 
      //Step 12: Instantiate the ns_out NetStream 
      ns_out = new NetStream(nc); 

      //Step 13: Attach the camera to the outgoing NetStream 
      ns_out.attachCamera(cam); 

      //Step 14: Define a local variable named h264Settings of type H264VideoStreamSettings 
      var h264Settings:H264VideoStreamSettings = new H264VideoStreamSettings(); 

      //Step 15: Set encoding profile and level on h264Settings 
      h264Settings.setProfileLevel(H264Profile.BASELINE, H264Level.LEVEL_3_1) 

      //Step 16: Set the bitrate and quality settings on the Camera object 
      cam.setQuality(90000, 90); 

      //Step 17: Set the video's height, width, fps, and whether it should maintain its capture size 
      cam.setMode(320, 240, 30, true); 

      //Step 18: Set the keyframe interval 
      cam.setKeyFrameInterval(15); 

      //Step 19: Set the outgoing video's compression settings based on h264Settings 
      ns_out.videoStreamSettings = h264Settings; 

      //Step 20: Publish the outgoing stream 
      ns_out.publish("livestream?adbe-live-event=liveevent"); 

     } 

     //Step 11: Un-comment this necessary callback function that checks bandwith (remains empty in this case) 
     public function onBWDone():void 
     { 
     } 
    } 

} 

如果有人能夠說明一點光至於爲什麼它不在移動攝像頭上運行,但在攝像頭上運行會很棒,甚至可以指向正確的方向

+0

我發現奇怪的是,您的示例實際上是在桌面模式下使用網絡攝像頭運行的,因爲我沒有看到將您的** CoolVideo **精靈添加到舞臺或顯示視圖的位置。 –

+0

@AdrianPirvulescu現在對不起,我會如何去執行,就像我會嘗試使用孩子添加一個凸輪? –

+0

你正在實例化新的CoolVideo();但不要添加它來查看。如何this.addElement(新的CollVideo());我有這樣的感覺,你沒有使用與你的桌面空氣應用程序相同的樣本 –

回答

0

仔細檢查所有的權限,如果在仿真環境中這幾乎是它必須是工作。

+1

謝謝@shinAcku –

1

要訪問Android中的設備攝像頭,您需要在中請求它下<android>

EG你appManifest.xml文件的部分:

<android> 
     <colorDepth>16bit</colorDepth> 
     <manifestAdditions><![CDATA[ 
      <manifest android:installLocation="auto"> 
       <uses-permission android:name="android.permission.CAMERA"/> 
      </manifest> 

     ]]></manifestAdditions> 
    </android> 
+0

我檢查了他們允許的權限仍然沒有任何@CyanAngel –

+0

嗯,好的。你是否曾嘗試將'Camera'輸出到像'VideoDisplay'這樣的UI元素來檢查你實際獲得的輸出。 – CyanAngel

相關問題