views:

358

answers:

2

I am making an application that plays the video stream from the user's local system (both Windows and Mac). I use the Camera.getCamera() method and in turn Camera.names to get a list of camera attached with the system.

Unfortunately, if the camera is already in use by another application, say a desktop application on user's system, the browser is crashed. Is there any way that I can detect if a specific camera from the list of available camera is already in use by any other application?

A: 

It sounds like there's more going on with your application than just the camera being in use by another application - calling Camera.getCamera() should just return null if another application is using the camera. Are you checking what Camera.getCamera() returns before you attempt to do anything with that value?

quoo
Thanks Quoo for your answer.The problem is that Camera.getCamera() returns null only if there is no camera attached with the system. It does return a Camera type object even if the camera is being used by another application. I have examined the properties of both cases when I get a camera object and there is no difference between them to help identify whether the camera is already in use or not. The crash problem starts from Privacy security box in flash player. If I click on "Allow" button, the browser crashes. If denied, nothing happens as expected.Hope you have a clear picture now.
Alex Fisherr
What code is called upon 'allow'? Do you have a status or activity event listener that it's making it to before crashing? I've tested my Camera apps for this situation frequently, and somehow never encountered this bug.
quoo
I haven't registered any listener on status events. Try your apps in two different browsers for this to happen. I don't know why it doesn't happen if you access same camera from multiple apps in the same browser. But with the camera in use in a desktop app or in another browser, it surely happens. Try one of your camera apps with youtube video uploader using webcam recording option in a different browser and you'll see what am I saying.
Alex Fisherr
A: 

It's true that with some webcam drivers, the Camera object will not be null even if the webcam is in use by another application. The only difference is that the ActivityEvent will never be fired after the camera is attached to the Video object if the camera is already in use.

I solved the issue by setting a timeout of 5 seconds and raising an event if the activity event had not yet fired:

public function WebCam(w:Number, h:Number, eventClient:Object) {
  _camera = Camera.getCamera();
  _micLive = Microphone.getMicrophone();
  _cameraWidth = w; // DEFAULT_CAMERA_WIDTH;
  _cameraHeight = h; // DEFAULT_CAMERA_HEIGHT;
  if (_camera != null) {
    video = new Video(_camera.width, _camera.height);   //displays video feed
    video.attachCamera(_camera);
    addChild(video); 
    _camera.addEventListener(StatusEvent.STATUS, cameraStatus);
    _camera.addEventListener(ActivityEvent.ACTIVITY, activityHandler);
    _camera.setMode(_cameraWidth, _cameraHeight, DEFAULT_CAMERA_FPS)

   //set timer to ensure that the camera activates.  If not, it might be in use by another application
    _waitingActivation = true;
    _timer = new Timer(TIMER_INTERVAL);
    _timer.addEventListener(TimerEvent.TIMER, activationTimeout);
    _timer.start();
  }
  else {
    //Security.showSettings(SecurityPanel.CAMERA)
  }
}
private function cameraStatus(event:StatusEvent):void{
    trace(_camera.muted);
}
private function activityHandler(e:ActivityEvent):void {
    trace('camera Activity');

    trace(_camera.activityLevel);
    if (e.activating){
        this._waitingActivation = false;
    }
}
protected function activationTimeout(e:TimerEvent):void{
    if (this._waitingActivation)
        this.dispatchEvent(new Event(WebCam.ACTIVATION_TIMEOUT, true));

    _timer.stop();
}

Hope this helps someone.

Laramie