Close webcam usage via actionscript

后端 未结 1 631
再見小時候
再見小時候 2021-01-14 14:40

Is there way, how to close webcam connection in actionscript. I am opening stream through Camera.getCamera(). Problem is, that after freeing webcam instance (i tried many wa

相关标签:
1条回答
  • 2021-01-14 15:12

    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;
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题