How do I detect in a Flex application if the camera is already in use by another application?

I am creating an application that plays a video stream from the user's local system (both Windows and Mac). I am using the Camera.getCamera () method, and in turn Camera.names, to get a list of cameras connected to the system.

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

+1


source to share


3 answers


It is true that with some webcam drivers, the Camera object will not be empty 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 connected to the Video object if the camera is already in use.

I solved the problem by setting a timeout of 5 seconds and raising the event if the activity event hadn't been fired yet:



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.

+3


source


In my experience, the only reason camera.currentFps is a constant number (not zero) for more than a few milliseconds is if the camera has just been disabled.

What I am doing is tracking the camera at time intervals, for example. every 5 seconds and collect sample data in rapid succession, say every 50ms for half a second.



If currentFps is constant across all samples, the camera just got disconnected from the network.

+2


source


It looks like there is more to your application than with a camera being used by another application - the call to Camera.getCamera () should simply return null if another application is using the camera. Are you checking what Camera.getCamera () is returning before trying to do anything with that value?

0


source







All Articles