如何在 Flex 应用程序中检测相机是否已被另一个应用程序使用? [英] How to detect in a Flex app if a camera is already in use by another application?

查看:29
本文介绍了如何在 Flex 应用程序中检测相机是否已被另一个应用程序使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个应用程序来播放来自用户本地系统(Windows 和 Mac)的视频流.我使用 Camera.getCamera() 方法,然后使用 Camera.names 来获取系统附带的相机列表.

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?

推荐答案

确实,对于某些网络摄像头驱动程序,即使其他应用程序正在使用网络摄像头,Camera 对象也不会为空.唯一的区别是,如果相机已在使用中,则在将相机附加到 Video 对象后,ActivityEvent 将永远不会被触发.

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.

我通过将超时设置为 5 秒并在活动事件尚未触发时引发事件来解决该问题:

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.

这篇关于如何在 Flex 应用程序中检测相机是否已被另一个应用程序使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆