zoukankan      html  css  js  c++  java
  • Flex(flash)检测摄像头的3种状态(是否被占用,没安装摄像头,正常)

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

    1.被占用

    2.没安装摄像头

    3.正常

      camera=Camera.getCamera();
                   if (camera == null)
                    {
                       if (Camera.names.length <= 0)
                        { 
                            
                            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("摄像头被占用");                    

    }                

    }           

      }

    代码说明:

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

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

  • 相关阅读:
    Ubuntu 更换软件源
    Ubuntu 配置 SOCKS5
    Ubuntu 配置 Sha-dow-socks
    frp(内网穿透)
    solr 远程代码执行(CVE-2019-12409)
    多线程处理爬虫
    python实现文件自动排序
    python 实现根据文件名自动分类移动至不同的文件夹
    Centos7如何开启任意端口服务
    centos7默认安装没有连接网络
  • 原文地址:https://www.cnblogs.com/jiahuafu/p/4094539.html
Copyright © 2011-2022 走看看