第一百二十一章(1 / 1)

第一百二十一章

關於GUID的生成原理與規則,讀者可以參閱鏈接:http://baike.baidu.com/view/ 185358.htm。

10.2 獲取Camera對象和Microphone對象

在第6章中我們曾經介紹過如何正確地獲取Camera對象和Microphone對象,在這裏,我們將實現這些函數和句柄並且應用到後續部分,首先來實現如何獲取Camera。

定義一個函數FindCamera,來獲取當前的Camera並且綁定其信息到camList對象。如前所述,我們需要考慮如下的攝像設備的問題:

? 客戶端機器上沒有安裝視頻驅動。

? 攝像頭存在,但沒有本地訪問權限。

? 攝像頭前有遮擋物,比如一些攝像頭有保護蓋。

? 另外一個程序正在使用攝像頭。

? 有多個驅動程序,但是默認的驅動無法在Flash裏工作。

? 驅動程序正常,但是攝像頭沒有正確連接。

? 有多個攝像頭需要選擇。

綜合第6章的代碼,我們可以用如下的方式來實現:

var camStatus:String;

var cam:Camera;

var curCamActivity = 0;

//Previous activityLevel.

var prevCamActivity = curCamActivity;

//How many times fps test failed.

var camfpsfailedcount = 0;

//How many times activity test failed.

var camactivityfailedcount = 0;

//Define how many times we are going to check.

var camcheckcount:int = 5;

publishBtn.enabled = false;

private function FindCamera(camIndex:int):void

{

cam:Camera = Camera.getCamera(camIndex);

//If no drivers were found.

if(cam ==null)

{

throw new Error("No Drivers Found");

}

cam. addEventListener(StatusEvent.STATUS, onCamStatus);

cam.addEventListener(ActivityEvent.ACTIVITY, onCamActivity);

Security.showSettings(SecurityPanel.**PRIVACY**);

}

function onCamStatus(e:StatusEvent)

{

switch (e.code)

{

case "Camera.Muted":

trace("User clicked Deny.");

break;

case "Camera.Unmuted":

trace("User clicked Accept.");

break;

}

}

function onCamActivity(e:ActivityEvent)

{

curCamActivity = cam.activityLevel;

}