问题
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 ways) LIGHT on webcam is still beam (tried on macbook pro).
回答1:
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;
}
}
}
来源:https://stackoverflow.com/questions/1483277/close-webcam-usage-via-actionscript