Flex (flash) detects three States of the camera (whether it is occupied, no camera is installed, normal)

Source: Internet
Author: User

SeriesArticleNavigation
  1. Index of flex and fms3 articles
  2. Free video adult chat room for air and free online remote video conferencing system (jointly created by flex and fms3 ))

In the videoProgramDuring the preparation process, we often need to use the camera. before using the camera, it is necessary to check the current status of the camera:

1. Occupied

2. No camera is installed

3. Normal

 

See the following:Code:

<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Export wedapplication 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 ("no camera installed ");
}
}
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)
{
// Video device available
Clearinterval (this. intervalid );
This. isbusycamera = false;
Alert. Show ("normal camera ");
}
Else
{
Times ++;
Trace ("Times =" + times. tostring ());

If (times> 30)
{
// Video Device Busy
Clearinterval (intervalid );
This. isbusycamera = true;
Alert. Show ("camera occupied ");
}
}
}

 

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: Using wedapplication>

 

Code Description:

Camera = NULL, the camera is not installed

If the camera is occupied, the camera. currentfps is definitely not greater than 0, but equal to 0.

 

Favorites and sharing

Add QQ bookmarks to Baidu souzang and Yahoo favorites

RSS subscribe to me What is RSS?




Dongguan. Net Club

Welcome to join

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.