Reputation: 89
I am currently using the code shown below to access and display the camera on an Android device. It works fine but instead of accessing the standard camera I would like to access the front facing camera. How can I modify the code below to do this ? Thanks in advance.
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);
}
Upvotes: 2
Views: 2381
Reputation: 994
The best way to get front camera on both android and on ios devices while developing application with Adobe Air is;
protected var _camera:Camera = null;
_camera = getCamera(CameraPosition.FRONT);
and then
private function getCamera(position:String):Camera
{
for (var i:uint = 0; i < Camera.names.length; ++i)
{
var cam:Camera = Camera.getCamera(String(i));
if (cam.position == position) return cam;
}
return Camera.getCamera();
}
By passing camera name sometime not working especially in ios based devices.
Upvotes: 0
Reputation: 629
Pass the Cam's Index value for your front camera in your Camera.getCamera();
, like:
var camIndex:String = "1";
var cam:Camera = Camera.getCamera(camIndex);
If the above modification doesn't change anything try changing the value of camIndex to "0", "2", "3" it depends on which index your front camera is registered. Try it!
Upvotes: 6