Highlighted

AS3 AIR 33 APK export nothing Camera device in Android mobile

Explorer ,
Feb 19, 2020

Copy link to clipboard

Copied

Hi there! I have try the code... Works fine in preview Mobile in Animate CC2020 with a webcam
but when I export the APK trought Air 33 and run the APK nothing occured.. white screen
Help me thanks

This is my simple code:

package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.*;
import flash.media.Camera;
import flash.media.Video;

public class Camera_setModeExample extends Sprite {
private var video:Video;

public function Camera_setModeExample() {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

var camIndex:String = "0";
var cam:Camera = Camera.getCamera(camIndex);

//var cam:Camera = Camera.getCamera();
var vid:Video = new Video();
vid.attachCamera(cam);
addChild(vid);
if (cam != null)
{
cam.addEventListener(StatusEvent.STATUS, statusHandler);
vid = new Video();
vid.attachCamera(cam);
}
function statusHandler(event:StatusEvent):void
{
if (!cam.muted)
{
vid.width = cam.width;
vid.height = cam.height;
addChild(vid);

}
cam.removeEventListener(StatusEvent.STATUS, statusHandler);
}

}
}
}

TOPICS
ActionScript, Error, Tablet

Views

319

Likes

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

AS3 AIR 33 APK export nothing Camera device in Android mobile

Explorer ,
Feb 19, 2020

Copy link to clipboard

Copied

Hi there! I have try the code... Works fine in preview Mobile in Animate CC2020 with a webcam
but when I export the APK trought Air 33 and run the APK nothing occured.. white screen
Help me thanks

This is my simple code:

package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.*;
import flash.media.Camera;
import flash.media.Video;

public class Camera_setModeExample extends Sprite {
private var video:Video;

public function Camera_setModeExample() {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

var camIndex:String = "0";
var cam:Camera = Camera.getCamera(camIndex);

//var cam:Camera = Camera.getCamera();
var vid:Video = new Video();
vid.attachCamera(cam);
addChild(vid);
if (cam != null)
{
cam.addEventListener(StatusEvent.STATUS, statusHandler);
vid = new Video();
vid.attachCamera(cam);
}
function statusHandler(event:StatusEvent):void
{
if (!cam.muted)
{
vid.width = cam.width;
vid.height = cam.height;
addChild(vid);

}
cam.removeEventListener(StatusEvent.STATUS, statusHandler);
}

}
}
}

TOPICS
ActionScript, Error, Tablet

Views

320

Likes

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
Feb 19, 2020 0
Adobe Community Professional ,
Feb 19, 2020

Copy link to clipboard

Copied

Hi.

 

Starting from AIR 24, permissions must be granted while the app is running and not when they are installed.

Beginning with Android 6.0 (API level 23), the users now need to grant permissions to apps while it is running, not when they install the application. To handle the permissions requests and status, we have introduced Permissions API for Android and iOS. The developers can request permissions for classes like Camera, Microphone, Geolocation, CameraRoll, CameraUI, File, and FileReference. The applications must be packaged with AIRSDK 24 or greater and must have SWF version 35 or later. Apps built using these APIs throw a dialog only on Android 6.0 and later. For Android 5.0 or earlier, you can continue to mention permissions in the application descriptor file.

 

Here is a code sample:

package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.PermissionEvent;
    import flash.media.Camera;
    import flash.media.Video;
    import flash.permissions.PermissionStatus;
      
    public class codeSnippet extends Sprite
    {
        private var video:Video;
        private var cam:Camera;
        public function codeSnippet()
        {
            super();
              
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
              
            if (Camera.isSupported)
            {
                cam = Camera.getCamera();
                  
                if (Camera.permissionStatus != PermissionStatus.GRANTED)
                {
                    cam.addEventListener(PermissionEvent.PERMISSION_STATUS, function(e:PermissionEvent):void {
                        if (e.status == PermissionStatus.GRANTED)
                        {
                            connectCamera();
                        }
                        else
                        {
                            // permission denied
                        }
                    });
                      
                    try {
                        cam.requestPermission();
                    } catch(e:Error)
                    {
                        // another request is in progress
                    }
                }
                else
                {
                    connectCamera();
                }
            }
        }
          
        private function connectCamera():void
        {
            video = new Video(640, 480);
            video.attachCamera(cam);
            addChild(video);
        }
    }
}

 

Here are the full release notes:

https://helpx.adobe.com/in/flash-player/release-note/fp_24_air_24_release_notes.html

(The part talking about permissons starts from "PERMISSIONS ON ANDROID AND IOS".)

 

I hope this helps.

 

 

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Feb 19, 2020 0
Explorer ,
Feb 19, 2020

Copy link to clipboard

Copied

Hi! you're very gentleman! I tried your code and works very fine... thanks.. but...

when I put inside my full code... don't work ..... no permission ask more.. Sorry... you can help me?

This is my code with your inside, I think that I positioned your code not in right place 🙂

package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Point;
import flash.media.Camera;
import flash.media.Video;
import flash.trace.Trace;
import flash.geom.Rectangle;
import flash.events.PermissionEvent;
import flash.permissions.PermissionStatus;

public class MotionDetection extends Sprite
{
private var _camera:Camera;
private var _video:Video;
private var _tracking:VideoTracker;
private var _tracker:TrackerMC = new TrackerMC();
private var _pos:Point = new Point();
private var _score:int = 0;
private var _w:uint = 640;
private var _h:uint = 480;
private var _ratioX:Number;
private var _ratioY:Number;
private var bound:Sprite = new Sprite();
private var mySprite:Sprite = new Sprite();
private var areaThreshold:int;
private var mt:VideoTracker;

var motion = false;


public function MotionDetection()
setup();
setupStage();
resize();
_pos.x = -50 // Definisce posizione fuori schermo iniziale del Tracker
_tracker.x = -50
mt = new VideoTracker(_video);
addEventListener(Event.ENTER_FRAME, loop);
addChild(_tracking);
addChild(_video);
addChild(_tracker);
{
public function Camera_setModeExample()
{
super();

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

if (Camera.isSupported)
{
cam = Camera.getCamera();

if (Camera.permissionStatus != PermissionStatus.GRANTED)
{
cam.addEventListener(PermissionEvent.PERMISSION_STATUS, function(e:PermissionEvent):void {
if (e.status == PermissionStatus.GRANTED)
{
connectCamera();
}
else
{
// permission denied
}
});

try {
cam.requestPermission();
} catch(e:Error)
{
// another request is in progress
}
}
else
{
connectCamera();
}
}
}

private function connectCamera():void
{
video = new Video(640, 480);
video.attachCamera(cam);
addChild(video);

setup();
setupStage();
resize();
_pos.x = -50
_tracker.x = -50

mt = new VideoTracker(_video);


addEventListener(Event.ENTER_FRAME, loop);


addChild(_tracking);
addChild(_video);


addChild(_tracker);

}

private function setup():void
{

_camera = Camera.getCamera();
_camera.setMode(_w, _h, 15);

_video = new Video(_w, _h);
_video.attachCamera(_camera);

_tracking = new VideoTracker(_video);

}

private function setupStage():void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, resize);

}

private function loop(e:Event):void

{

_tracking.track();

_pos = _tracking.pos;
_pos.x *= _ratioX;
_pos.y *= _ratioY;

}

}

private function resize(e:Event=null):void
{
_ratioX = sW/_w;
_ratioY = sH/_h;
_tracker.y = sH*.5;

}

public function get sW():uint { return stage.stageWidth; }
public function get sH():uint { return stage.stageHeight; }

}
}

Likes

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
Reply
Loading...
Feb 19, 2020 0
Adobe Community Professional ,
Feb 19, 2020

Copy link to clipboard

Copied

Hi.

 

Your code has formatting problems.

 

The setup instructions are outside of the constructor's curly braces. And you defined some methods inside of the constructor's curly braces.

 

With that being said, your code should be organized like this:

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.media.Camera;
	import flash.media.Video;
	import flash.trace.Trace;
	import flash.geom.Rectangle;
	import flash.events.PermissionEvent;
	import flash.permissions.PermissionStatus;

	public class MotionDetection extends Sprite
	{
		private var _camera:Camera;
		private var _video:Video;
		private var _tracking:VideoTracker;
		private var _tracker:TrackerMC = new TrackerMC();
		private var _pos:Point = new Point();
		private var _score:int = 0;
		private var _w:uint = 640;
		private var _h:uint = 480;
		private var _ratioX:Number;
		private var _ratioY:Number;
		private var bound:Sprite = new Sprite();
		private var mySprite:Sprite = new Sprite();
		private var areaThreshold:int;
		private var mt:VideoTracker;
		private var motion = false;

		public function MotionDetection()
		{
			super();
			setup();
			setupStage();
			resize();
			_pos.x = -50 // Definisce posizione fuori schermo iniziale del Tracker
			_tracker.x = -50
			mt = new VideoTracker(_video);
			addEventListener(Event.ENTER_FRAME, loop);
			addChild(_tracking);
			addChild(_video);
			addChild(_tracker);
		}

		public function Camera_setModeExample()
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;

			if (Camera.isSupported)
			{
				cam = Camera.getCamera();

				if (Camera.permissionStatus != PermissionStatus.GRANTED)
				{
					cam.addEventListener(PermissionEvent.PERMISSION_STATUS, function (e:PermissionEvent):void
					{
						if (e.status == PermissionStatus.GRANTED)
						{
							connectCamera();
						}
						else
						{
							// permission denied
						}
					});

					try
					{
						cam.requestPermission();
					}
					catch (e:Error)
					{
						// another request is in progress
					}
				}
				else
				{
					connectCamera();
				}
			}
		}

		private function connectCamera():void
		{
			video = new Video(640, 480);
			video.attachCamera(cam);
			addChild(video);
			setup();
			setupStage();
			resize();
			_pos.x = -50
			_tracker.x = -50
			mt = new VideoTracker(_video);
			addEventListener(Event.ENTER_FRAME, loop);
			addChild(_tracking);
			addChild(_video);
			addChild(_tracker);
		}

		private function setup():void
		{
			_camera = Camera.getCamera();
			_camera.setMode(_w, _h, 15);
			_video = new Video(_w, _h);
			_video.attachCamera(_camera);
			_tracking = new VideoTracker(_video);
		}

		private function setupStage():void
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.addEventListener(Event.RESIZE, resize);
		}

		private function loop(e:Event):void
		{
			_tracking.track();
			_pos = _tracking.pos;
			_pos.x *= _ratioX;
			_pos.y *= _ratioY;
		}

		private function resize(e:Event = null):void
		{
			_ratioX = sW / _w;
			_ratioY = sH / _h;
			_tracker.y = sH * .5;
		}

		public function get sW():uint
		{
			return stage.stageWidth;
		}

		public function get sH():uint
		{
			return stage.stageHeight;
		}
	}
}

 

 

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Feb 19, 2020 0
Explorer ,
Feb 20, 2020

Copy link to clipboard

Copied

Hi JC! your're great and really "AS3 Jedi Master" but.. nope... I get a error... I tried but don't know solve it...

Line 186, Column 4 1013: The private attribute may be used only on class property definitions.

JC.. I ask to you an ultimate effort... If  I send you the FLA source.. may you try it?

If you mean a donation... I'll donate to you... I say really... 

Thanks so much really again

Likes

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
Reply
Loading...
Feb 20, 2020 1
Adobe Community Professional ,
Feb 20, 2020

Copy link to clipboard

Copied

Sure! Please post a link to the file here or PM me and I'll be glad to help.

 

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Feb 20, 2020 0
Explorer ,
Feb 20, 2020

Copy link to clipboard

Copied

Your're very gentle JC...
I have send you the complete project in your private message...
Thanks so much again

Then you have to tell me how much I have to pay you back!
Micky

Likes

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
Reply
Loading...
Feb 20, 2020 0
Explorer ,
Feb 20, 2020

Copy link to clipboard

Copied

Hi! Thanks I try it now!!!

Likes

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
Reply
Loading...
Feb 20, 2020 0
Explorer ,
Feb 20, 2020

Copy link to clipboard

Copied

JC! you've save my life.. it's the same of "Save the Ryan soldier"! 🙂
Works fine.. i get the camera in my tablet... I think the same in my smarthphone... I'll try

Now I must only make a full screen  camera... because for now is always small in the left side of the screen.. but I'll works hardly for it!!! 🙂

You have to tell me where to get you pastries! I want to make you a donation ...
Tell me 

Likes

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
Reply
Loading...
Feb 20, 2020 1
Adobe Community Professional ,
Feb 20, 2020

Copy link to clipboard

Copied

This is awesome! I'm very glad you managed to solve the issue! \o/

 

I'm pretty confident this is going to work on your phone as well and please let me know if you need help with the fullscreen challenge.

 

Have a nice weekend!

 

 

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Feb 20, 2020 0