I have tried to check activity, fps, status. nothing is triggered when an active camera is unplugged in as3/air. Has anyone found a working way? In my cas开发者_运维知识库e i have a kiosk running air 2.7 running two webcams. In some cases a usb webcam might be unplugged and plugged back in. I have been trying find a way to detect when its unplugged so I can restart it. Ideas?
Unfortunately i have no USB camera to test this with (only got insight).
You could try ActivityEvent and set motionlevel to some low value.
ActivityEvent will give you response if and when motion is detected in camera. I belive when Camera is physically disconnected, activity event should trigger since no activity will be detected.
Here's a piece of example:
import flash.media.Camera;
import flash.display.Stage;
import flash.media.Video;
import flash.events.ActivityEvent;
import flash.events.StatusEvent;
var camera:Camera = Camera.getCamera();
camera.setMode(stage.stageWidth, stage.stageHeight,25);
camera.addEventListener(ActivityEvent.ACTIVITY, activityEventHandler,false,0,true);
camera.setMotionLevel(3);
var video:Video = new Video();
video.width = stage.stageWidth;
video.height = stage.stageHeight;
video.attachCamera(camera);
addChild(video);
function activityEventHandler(a:ActivityEvent):void{
trace('Motion detected: '+a.activating);
}
Note: setMotionlevel default value is 50 so if you set it to eg. 3 then camera still notices some small changes, even eye-blinking. That would help you to detect if there is any kind of motion at all. If no motion is detected then camera is probably dead.
You maybe even can use motionlevel as 1, but this value is very sensitive and even slightest change in room lightning is probably detected as motion.
Let me know if that helps, would be interesting to hear about this in practice with real USB camera.
精彩评论