Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus
Accepted Solution

Camera access - works in AIR Player not not on Playbook

Good day everyone. I am using the following code to take a snapshot from the webcam and then save it with a button. It works when I run the app in the AIR player but on the Playbook it's not accessing the camera, nothing shows up.

 

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
		xmlns:mx="library://ns.adobe.com/flex/mx"
		xmlns:s="library://ns.adobe.com/flex/spark"
		actionBarVisible="false"  creationComplete="init()" overlayControls="false"
		tabBarVisible="false">
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	<s:Panel id="p" top="1" width="1024" height="600" backgroundAlpha="0.0" horizontalCenter="0">
		<s:Panel id="imageViewer" top="-32" width="1024" height="600" backgroundAlpha="0.0" horizontalCenter="0"/>
		<s:Panel id="preview" top="-32" width="1024" height="600" backgroundAlpha="0.0" horizontalCenter="0"/>			
		<DrawingArea xmlns="*" id="drawingArea" y="-32" width="100%" height="509"/>
	</s:Panel>
	<fx:Script>
		<![CDATA[
			import com.tinkerlog.WebCam;
			import com.tinkerlog.util.Base64;
			
			import flash.media.Camera;
			
			import mx.core.UIComponent;
			import mx.graphics.codec.JPEGEncoder;
			import mx.graphics.codec.PNGEncoder;
			
			private var webCam:WebCam;
			
			private function init():void {
				webCam = new WebCam(1024, 600);
				var ref:UIComponent = new UIComponent();
				preview.removeAllElements();
				preview.addElement(ref);
				ref.addChild(webCam);	
			}
			private function takeSnapshot():void {
				imageViewer.visible = true;
				preview.visible=false;
				imageViewer.width = preview.width;
				imageViewer.height = preview.height;
				var uiComponent : UIComponent = new UIComponent();
				uiComponent.width = webCam.width;
				uiComponent.height = webCam.height;
				var photoData:Bitmap = webCam.getSnapshot();
				var photoBitmap:BitmapData = photoData.bitmapData;
				uiComponent.addChild(photoData);
				imageViewer.removeAllElements();
				imageViewer.addChild(uiComponent);
			}
			private function deleteSnapshot():void {
				imageViewer.removeAllElements();
			}
			
			public function save():void
			{
				var bd:BitmapData = new BitmapData(p.width, p.height);
				bd.draw(this);
				
				var barr:ByteArray = (new PNGEncoder()).encode(bd);
				(new FileReference()).save(barr, "capture.png");
			}
		]]>
	</fx:Script>
</s:View>

 

 

 

Developer
Posts: 231
Registered: ‎05-03-2011
My Device: PlayBook V1 and proud of it :-)
My Carrier: Legs

Re: Camera access - works in AIR Player not not on Playbook

[ Edited ]

You cant' take a pic yet, the BB SDK doesn't have the API for it, it will work desktop, because your using Adobes API to get an image, go to this thread here.

 

BB SDK API Camera

Keep the Forum productive and useful for all. Click Kudos button if I've helped you. Select Solved to help everyone.

PlayBook qualifying app - Pandoras' Lights
Blog - CoCopia.co.uk Catch me on Twitter cocopia_apps
Developer
Posts: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus

Re: Camera access - works in AIR Player not not on Playbook

Developer
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)
My Carrier: Regional

Re: Camera access - works in AIR Player not not on Playbook

Don't forget, you need to add the permissions for it in your blackberry-tablet.xml file.

    <action>use_camera</action>

 It should prompt you when launching the app to allow permission to the camera. You might also want to add:

    <action>access_shared</action>

 

You might want to take a look at this article.

Developer
Posts: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus

Re: Camera access - works in AIR Player not not on Playbook

Eureka! I had <action>access_shared</action> but didnt know about <action>use_camera</action>. Thats a great link, can't wait to do some bedtime reading on my PB! Many thanks John :smileyhappy:

Developer
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)
My Carrier: Regional

Re: Camera access - works in AIR Player not not on Playbook

Glad you got it going!