开发者

how to get attachCamera() when load page,so when people load or refresh page they will ask for for their camera access first?

开发者 https://www.devze.com 2023-03-09 14:06 出处:网络
i have used this code to get 开发者_开发知识库camera access how i can load it on page load private function startVideo():void

i have used this code to get 开发者_开发知识库camera access how i can load it on page load

    private function startVideo():void
        {
            if (true) // TODO: Recognize no video settings
            {
                var camera:Camera = Camera.getCamera(cameraIndex.toString());

                if (camera)
                {
                    vidMe.attachCamera(camera);
                    if (outgoingStream)
                    {
                        outgoingStream.attachCamera(camera);
                    }
                }
            }
            else
            {
                vidMe.attachCamera(null);
                if (outgoingStream)
                {
                    outgoingStream.attachCamera(null);
                }
            }
        }


Flash shows the camera request dialog the first time you call attachCamera(). To have a user be asked upfront, before your flash application reaches any functionality, I would suggest adding it upfront in our constructor.

This dummy function puts together a fake NetConnection, and connects it to no server. Going through this upfront will present a user with the camera use dialog while your flash application is loading, thus happening on page refresh or initial load.

private function ensurePermissions() : void {
    var unusedNetConnection : NetConnection = new NetConnection()
    unusedNetConnection.connect( null );

    var ensureCamPermissions : NetStream = new NetStream( unusedNetConnection );
    ensureCamPermissions.attachCamera( myCamera );

    try {
        ensureCamPermissions.close();
        unusedNetConnection.close();
    } catch( error:Error ) {
        // Ignore any errors here
    } finally {
        ensureCamPermissions = null;
        unusedNetConnection = null;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消