本博推荐文章快速导航: Sql Server2005 Transact-SQL 新兵器学习 MCAD学习 代码阅读总结 ASP.NET状态管理 DB(数据库) WAP WinForm Flex,Fms

Flex(flash)检测摄像头的3种状态(是否被占用,没安装摄像头,正常)

系列文章导航
  1. Flex,Fms3相关文章索引
  2. Air版免费视频成人聊天室,免费网络远程视频会议系统((Flex,Fms3联合打造))

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

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

 

收藏与分享

收藏到QQ书签 添加到百度搜藏 添加到百度搜藏 添加到雅虎收藏 分享到饭否 收藏到就喜欢网络收藏夹

RSS订阅我 什么是RSS?

feedsky    http://wap.feedsky.com/aierongrss    E-mail
订阅到雅蛙       使用RSS邮天下订阅    订阅到有道阅读
订阅到抓虾    鲜果阅读器订阅图标    Add to Google
訂閱 Bloglines    哪吒提醒    Subscribe in NewsGator Online

东莞.net俱乐部

东莞.net俱乐部 欢迎您的加入

posted @ 2009-02-20 08:01 aierong 阅读(...) 评论(...) 编辑 收藏