Close webcam usage via actionscript

折月煮酒 提交于 2019-12-01 08:59:29

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

The below example demonstrates the code. When you click on the stage, Camera is toggled 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;
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!