• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Camera is in use ??

New Here ,
Mar 23, 2010 Mar 23, 2010

Copy link to clipboard

Copied

Hi all,

      How to detect camera is in use or not ??  Adobe says, if Camera.getCamera(); returns null, it means camera not installed, or in use ,

i use below, then when i start swf, first one is ok, but then i start new instance of app, it throws and error " .... flash 10 r2has stopped"

how can i solve that problem...

cam = Camera.getCamera();
  
   if (!cam) {
                myTextField.text = "No camera is installed.";
               
            } else {
                myTextField.text = "Connecting";
                connectCamera();
            }

    private function connectCamera():void {
                var vid:Video = new Video(150, 150);
                vid.x = 10;
                vid.y = 10;
                vid.attachCamera(cam);
                addChild(vid);  

                 }

thanks..

Views

925

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Mar 23, 2010 Mar 23, 2010

Copy link to clipboard

Copied

What adobe says is correct. Camera.getCamera() returns the available camera on the system or null if camera is not installed or not free.

To kill a netstream simply do following,

netStream.close();

netStream = null;

that should work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 23, 2010 Mar 23, 2010

Copy link to clipboard

Copied

I use code below,

get an error like that

1. instance working good,

2.instance give an erro when i clicked allow for camera ???

error.png

package {
    import flash.display.Sprite;
    import flash.media.Camera;
    import flash.media.Video;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.events.StatusEvent;
    import flash.events.MouseEvent;
    import flash.system.SecurityPanel;
    import flash.system.Security;

    public class Camera_getCameraExample extends Sprite {
        private var myTextField:TextField;
        private var cam:Camera;
        private var t:Timer = new Timer(1000);
       
        public function Camera_getCameraExample() {
            myTextField = new TextField();
            myTextField.x = 10;
            myTextField.y = 10;
            myTextField.background = true;
            myTextField.selectable = false;
            myTextField.autoSize = TextFieldAutoSize.LEFT;   
       
            cam = Camera.getCamera();
           
            if (!cam) {
                myTextField.text = "No camera is installed.";
               
            } else if (cam.muted) {
                myTextField.text = "To enable the use of the camera,\n"
                                 + "please click on this text field.\n"
                                 + "When the Flash Player Settings dialog appears,\n"
                                 + "make sure to select the Allow radio button\n"
                                 + "to grant access to your camera.";

                myTextField.addEventListener(MouseEvent.CLICK, clickHandler);

            }else {
                myTextField.text = "Connecting";
                connectCamera();
            }
  
            addChild(myTextField);

            t.addEventListener(TimerEvent.TIMER, timerHandler);
        }

        private function clickHandler(e:MouseEvent):void {
            Security.showSettings(SecurityPanel.PRIVACY);

            cam.addEventListener(StatusEvent.STATUS, statusHandler);

            myTextField.removeEventListener(MouseEvent.CLICK, clickHandler);
        }

        private function statusHandler(event:StatusEvent):void {

            if (event.code == "Camera.Unmuted") {
                connectCamera();
                cam.removeEventListener(StatusEvent.STATUS, statusHandler);
            }
        }

        private function connectCamera():void {
                var vid:Video = new Video(cam.width, cam.height);
                vid.x = 10;
                vid.y = 10;
                vid.attachCamera(cam);
                addChild(vid);  

                t.start();
        }

        private function timerHandler(event:TimerEvent):void {
            myTextField.y = cam.height + 20;
            myTextField.text = "";
            myTextField.appendText("bandwidth: " + cam.bandwidth + "\n");
            myTextField.appendText("currentFPS: " + Math.round(cam.currentFPS) + "\n");
            myTextField.appendText("fps: " + cam.fps + "\n");
            myTextField.appendText("keyFrameInterval: " + cam.keyFrameInterval + "\n");
        }
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 23, 2010 Mar 23, 2010

Copy link to clipboard

Copied

What combination of platform and camera device are you experiencing a flashplayer crash with? I've never encountered this behavior.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 23, 2010 Mar 23, 2010

Copy link to clipboard

Copied

hi JayCharles , flash cs4, windows 7, ie8 i use. Thanks ...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 23, 2010 Mar 23, 2010

Copy link to clipboard

Copied

I've found that I need to manually release the camera. A function that calls:

vid.attachCamera(null);

Hopefully that is the piece that works for you too.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 23, 2010 Mar 23, 2010

Copy link to clipboard

Copied

hi yun,  actually i need to detect camera is in use or not ?? because , while a application using the cam, another app shouldnt allow user to use cam. When the app does, crashing. So i need a sample shows, check camera if in use or not before start..

Thanks...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 23, 2010 Mar 23, 2010

Copy link to clipboard

Copied

I see, my mistake. I understand what you mean now. Have you tried to instantiate the Camera object in a Try/Catch block to maybe capture the error without crashing your flash player?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 24, 2010 Mar 24, 2010

Copy link to clipboard

Copied

LATEST

Hi yun, i have already tried to use try/catch but, app is crashing down , when started Thanks for your help .

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines