• Flex(flash)检测摄像头的3种状态


    在视频程序的编写过程中,我们经常要使用摄像头,在使用摄像头前有必要对摄像头的现有状态做个检测:

    1.被占用

    2.没安装摄像头

    3.正常

    看下面代码:


    http://www.adobe.com/2006/mxml"
        layout="absolute" creationComplete="init()">


        
                import mx.controls.Alert;
                private var camera:Camera;
                private var isExistsCamera:Boolean=false;
                private var isBusyCamera:Boolean=false;
                private var intervalId:uint;
                private var times:int;

                private function init():void
                {
                    camera=Camera.getCamera();
                   if (camera == null)
                    {
                       if (Camera.names.length <= 0)
                        {
                            this.isExistsCamera=false;
                            Alert.show("没安装摄像头");
                        }
                    }
                    else
                    {
                        this.vdpaly.attachCamera(this.camera);
                        this.isCameraBusy();
                    }
                }


                private function isCameraBusy():void
                {
                    this.intervalId=setInterval(callback,50);
                }

                private function callback():void
                {
                    trace("currentFPS=" + camera.currentFPS.toString());

                   if (camera.currentFPS > 0)
                    {
                        //视频设备可用
                        clearInterval(this.intervalId);
                        this.isBusyCamera=false;
                        Alert.show("摄像头正常");
                    }
                    else
                    {
                        times++;
                        trace("times=" + times.toString());

                        if (times > 30)
                        {
                            //视频设备忙
                            clearInterval(intervalId);
                            this.isBusyCamera=true;
                            Alert.show("摄像头被占用");
                        }
                    }
                }

                 private function cl():void
                {
                    Alert.show(this.camera.currentFPS.toString());
                }

            ]]>
       

    代码说明:

    camera == null,那么就是没安装摄像头

    如果摄像头被占用,那么camera.currentFPS 肯定不会大 于0,而是等于0

  • 相关阅读:
    【大数据】WAL预写日志
    【Teradata】运维3个9或4个9代表什么
    【大数据-文摘笔记】Veritas NBU简介
    【Teradata】DSA+NBU备份1148错误
    【大数据-文摘笔记】京东HBase平台进化与演进
    【Teradata 工具】使用SQL Assistant连接每次都需要重新输入口令
    【金融】银行有什么分类
    VS 创建虚拟目录失败,映射到其他文件夹!
    js cookie读取
    解决“在证书存储区中找不到清单签名证书”
  • 原文地址:https://www.cnblogs.com/bmate/p/1868196.html
Copyright © 2020-2023  润新知