惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
T
Tailwind CSS Blog
Webroot Blog
Webroot Blog
S
Secure Thoughts
N
News and Events Feed by Topic
月光博客
月光博客
TaoSecurity Blog
TaoSecurity Blog
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
N
News | PayPal Newsroom
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
小众软件
小众软件
Recent Commits to openclaw:main
Recent Commits to openclaw:main
P
Privacy & Cybersecurity Law Blog
GbyAI
GbyAI
K
Kaspersky official blog
WordPress大学
WordPress大学
P
Proofpoint News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 叶小钗
W
WeLiveSecurity
Jina AI
Jina AI
The Cloudflare Blog
Project Zero
Project Zero
Simon Willison's Weblog
Simon Willison's Weblog
V
Vulnerabilities – Threatpost
L
LangChain Blog
Forbes - Security
Forbes - Security
PCI Perspectives
PCI Perspectives
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
Recorded Future
Recorded Future
博客园 - 【当耐特】
H
Heimdal Security Blog
A
About on SuperTechFans
Cisco Talos Blog
Cisco Talos Blog
T
Threat Research - Cisco Blogs
云风的 BLOG
云风的 BLOG
Spread Privacy
Spread Privacy
L
LINUX DO - 最新话题
L
Lohrmann on Cybersecurity
Last Week in AI
Last Week in AI
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
I
Intezer
Martin Fowler
Martin Fowler
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint

博客园 - OldHawk

android:themes.xml android:style.xml How to merge two images into one using Actionscript Fms3中client端与server端交互方式汇总 推荐几个Adobe Flex Builder 3的插件(代码格式化和fms服务器通讯文件(main.asc)编写) - OldHawk flex4中list与itemRenderer项目渲染器中子对象之间访问 install flashpolicyd Linux环境如何升级Python linux运行级别查看并更改研究 Flash builder 4 (Flex builder 4) 正式版序列号生成器 (转)基于svnserve的服务器,权限文件authz配置的常见问题及解答 Linux下SVN安装配置记录 (转)谈linux安全设置 Linux安全配置步骤简述 对linux安全设置中需要注意和掌握的地方 Linux操作系统下SSH默认22端口修改方法 图片与二进制及字符相互换化(转) MSDN帮助文档 "无法显示该网页" 的问题解决方案(转) - OldHawk 修改flex应用默认的装载界面
Flex(flash)检测摄像头的3种状态(是否被占用,没安装摄像头,正常) - OldHawk - 博客园
OldHawk · 2010-12-05 · via 博客园 - OldHawk
 

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

1.被占用

2.没安装摄像头

3.正常

看下面代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute" creationComplete="init()">


    <mx:Script>
        <![CDATA[


            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());
            }

        ]]>
    </mx:Script>


    <mx:VideoDisplay   id="vdpaly"  click="cl()" x="44" y="64" width="232" height="236"/>


</mx:WindowedApplication>

代码说明:

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

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