Просмотр полной версии : Определить "занятость" камеры
Можно ли определить, доступна ли камера? Не факт наличия устройства, а работает она или нет. К примеру, если в системе несколько устройств, а устройство по умолчанию не доступно, т.к. используется другим приложением.
AlexCooper
13.01.2013, 17:30
свойство camera.muted
// Imports
import flash.media.Camera;
import flash.media.Video;
import flash.events.MouseEvent;
// Variables
var _camera:Camera = null;
var _video:Video = null;
// Add available cameras to ComboBox
function displayAvailableCameras():void
{
// Loop thru cameras
for(var i:int = 0; i < Camera.names.length; i++)
{
// Add items
var cam:Camera = Camera.getCamera(String(i)) as Camera;
comboBox.addItem( { label:cam.name, data:cam.name } );
// Select selected value to “USB Video Class Video” if it exists
if(cam.name == “USB Video Class Video”) comboBox.selectedIndex = i;
}
}
// Check to see if there is a camera available and use it if available
function addCamera(e:MouseEvent):void
{
trace(“addCamera()”);
// Tell user something is happening
infoText.text = “Checking for a webcam”
// Webcam does not exists at all.
if (Camera.getCamera() == null)
{
trace(“You need a webcam”);
// Inform user that they need a webcam on their computer here
infoText.text = “Please connect a webcam”
}
// Webcam exists
else
{
trace(“You have a webcam.”);
// Set the desired camera by passing the selected index as a String
_camera = Camera.getCamera( String(comboBox.selectedIndex) );
// Display camera feed as a video
displayVideo();
}
}
// Display the video using the camera feed.
function displayVideo():void
{
trace(“displayVideo()”);
// Create video object
_video = new Video();
// Attach camera
_video.attachCamera(_camera);
// Add video to stage
addChild(_video);
}
// Show list of available cameras in ComboBox
displayAvailableCameras()
// Button functionality
checkButton.addEventListener( MouseEvent.CLICK, addCamera );
checkButton.buttonMode = true;
AlexCooper, спасибо за пример, но думаю, что вы заблуждаетесь, вот (http://help.adobe.com/ru_RU/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#muted)
http://help.adobe.com/ru_RU/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#getCamera()
Если getCamera() возвращает значение null, это значит, что камера используется другим приложением или что в системе не установлены камеры. Определить, установлены ли камеры, можно с помощью свойства names.length.
import flash.media.Camera;
var _cam:Camera;
var arr:Array = Camera.names;
var length:int = arr.length;
for(var i:int=0; i<length; i++){
_cam=Camera.getCamera(i.toString());
trace(i, _cam);
}
При уже работающей камере нет ни одного null (в моем случае из 3х), т.е. метод getCamera возвращает объект, не зависимо от того занят он или нет.
Работает на vBulletin ® версия 3.7.3. Copyright ©2000-2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Copyright © 1999-2008 Flasher.ru. All rights reserved.