【问题标题】:Flash builder 4.6 camera app mobileFlash builder 4.6 相机应用手机
【发布时间】:2014-03-05 11:51:48
【问题描述】:

大家好,我正在使用 Flash builder 4.6 开发移动相机应用程序。 我的问题是我可以让摄像头与网络摄像头一起工作,但不能让摄像头与要部署的移动摄像头一起工作。我正在使用 AIR 尝试流式传输。
这就是我如何称呼我的按钮:

<?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
        {
        }
    }

}

如果有人能解释一下为什么它不在移动摄像头上运行,但在网络摄像头上运行,那就太好了,甚至可以为我指明正确的方向

【问题讨论】:

  • 我觉得奇怪的是,您的示例实际上是在带有网络摄像头的桌面模式下运行的,因为我看不到您的 CoolVideo 精灵被添加到舞台或显示器的地方查看。
  • @AdrianPirvulescu 抱歉,现在我将如何实施,就像我尝试使用孩子添加凸轮一样??
  • 你正在实例化新的 CoolVideo();但不要将其添加到视图中。 this.addElement(new CollVideo()); 怎么样?我感觉您使用的示例与桌面空气应用程序中的示例不同

标签: actionscript-3 flash air flash-builder android-camera


【解决方案1】:

要在 Android 中访问设备摄像头,您需要在 appManifest.xml 文件的 &lt;uses-permision&gt; 部分中请求它,该部分位于 &lt;android&gt; 根目录下

EG:

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

        ]]></manifestAdditions>
    </android>

【讨论】:

  • 我检查了他们被允许的权限仍然没有@CyanAngel
  • 嗯,好的。您是否尝试过将Camera 输出到像VideoDisplay 这样的UI 元素来检查您实际获得的输出。
【解决方案2】:

仔细检查您的所有权限,就好像它在模拟环境中工作一样,这几乎是它必须的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-21
    • 2012-08-27
    • 2014-07-14
    • 2012-05-10
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多