Close webcam usage with actionscript

Is there any way how to close webcam connection in actionscript. I open the stream through Camera.getCamera (). The problem is that after releasing the webcam instance (I tried many ways) LIGHT on the webcam is still a ray (tested on macbook pro).

+3
source share
1 answer

You can simply call video.attachCamera(null)to release the camera.

The example below shows the code. When you click on a scene, the camera switches on / off.

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.media.Camera;
    import flash.media.Video;

    public class testAS3 extends Sprite
    {
        public var cam:Camera;
        public var video:Video;
        public var camOn:Boolean = false;


        public function testAS3()
        {
            cam = Camera.getCamera();
            video = new Video();
            addChild(video);

            stage.addEventListener(MouseEvent.CLICK,toggleCamera);
        }

        public function toggleCamera(evt:Event):void {
            if (camOn){
                video.attachCamera(null);
            } else {
                video.attachCamera(cam);
            }

            camOn = !camOn;
        }
    }
}
+3
source

Source: https://habr.com/ru/post/1718635/


All Articles