live camera preview in the android emulator

17
Search Home Live camera preview in the Android emulator I've been looking into getting a live camera preview working in the Android emulator. Currently the Android emulator just gives a black and white chess board animation. After having a look around I found the web site of Tom Gibara who has done some great work to get a live preview working in the emulator. The link to his work can be found here. The basics are that you run the WebcamBroadcaster as a standard java app on your PC. If there are any video devices attached to you PC, it will pick them up and broadcast the frames captured over a socket connection. You then run a SocketCamera class as part of an app in the android emulator, and as long as you have the correct ip address and port it should display the captured images in the emulator. On looking into Tom's code I saw that it seemed to be written for an older version of the Android API so I thought I'd have a go at updating it. As a starting point I'm going to use the CameraPreview sample code available on the android developers website. My aim was to take this code and with as little changes as possible make it so it could be used to give a live camera preview in the emulator. So the first thing I did was to create a new class called SocketCamera, this is based on Tom's version of the SocketCamera, but unlike Tom's version I am trying to implement a subset of the new camera class android.hardware.Camera and not the older class android.hardware.CameraDevice. Please keep in mind that I've implemented just a subset of the Camera class API. The code was put together fairly quickly and is a bit rough round the edges. Anyhow, here's my new SocketCamera class: package com.example.socketcamera; import java.io.IOException; import java.io.InputStream; import java.net.InetSocketAddress; import java.net.Socket; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.hardware.Camera; import android.hardware.Camera.Size; import android.util.Log; import android.view.SurfaceHolder; public class SocketCamera { private static final String LOG_TAG = "SocketCamera:"; private static final int SOCKET_TIMEOUT = 1000; static private SocketCamera socketCamera; private CameraCapture capture; private Camera parametersCamera; private SurfaceHolder surfaceHolder; //Set the IP address of your pc here!! private final String address = "192.168.1.12"; private final int port = 9889; private final boolean preserveAspectRatio = true; private final Paint paint = new Paint(); INTERFUSER Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu... 1 of 17 9/5/2011 1:00 PM

Upload: gvravindranath

Post on 02-Oct-2014

367 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Live Camera Preview in the Android Emulator

SearchHome

Live camera preview in the Android emulator

I've been looking into getting a live camera preview working in the Androidemulator. Currently the Android emulator just gives a black and white chess boardanimation. After having a look around I found the web site of Tom Gibara who hasdone some great work to get a live preview working in the emulator. The link to hiswork can be found here. The basics are that you run the WebcamBroadcaster as astandard java app on your PC. If there are any video devices attached to you PC, itwill pick them up and broadcast the frames captured over a socket connection.You then run a SocketCamera class as part of an app in the android emulator, andas long as you have the correct ip address and port it should display the capturedimages in the emulator. On looking into Tom's code I saw that it seemed to bewritten for an older version of the Android API so I thought I'd have a go atupdating it. As a starting point I'm going to use theCameraPreview sample code available on the android developers website. My aimwas to take this code and with as little changes as possible make it so it could beused to give a live camera preview in the emulator.

So the first thing I did was to create a new class called SocketCamera, this is basedon Tom's version of the SocketCamera, but unlike Tom's version I am trying toimplement a subset of the new camera class android.hardware.Camera and not theolder class android.hardware.CameraDevice. Please keep in mind that I'veimplemented just a subset of the Camera class API. The code was put togetherfairly quickly and is a bit rough round the edges. Anyhow, here's my newSocketCamera class:

package com.example.socketcamera;

import java.io.IOException;import java.io.InputStream;import java.net.InetSocketAddress;import java.net.Socket;

import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.Rect;import android.hardware.Camera;import android.hardware.Camera.Size;import android.util.Log;import android.view.SurfaceHolder;

public class SocketCamera {

private static final String LOG_TAG = "SocketCamera:"; private static final int SOCKET_TIMEOUT = 1000;

static private SocketCamera socketCamera; private CameraCapture capture; private Camera parametersCamera; private SurfaceHolder surfaceHolder;

//Set the IP address of your pc here!! private final String address = "192.168.1.12"; private final int port = 9889;

private final boolean preserveAspectRatio = true; private final Paint paint = new Paint();

I N TE R F U SE R

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

1 of 17 9/5/2011 1:00 PM

Page 2: Live Camera Preview in the Android Emulator

private int width = 240; private int height = 320; private Rect bounds = new Rect(0, 0, width, height);

private SocketCamera() { //Just used so that we can pass Camera.Paramters in getters and setters parametersCamera = Camera.open(); }

static public SocketCamera open() { if (socketCamera == null) { socketCamera = new SocketCamera(); }

Log.i(LOG_TAG, "Creating Socket Camera"); return socketCamera; }

public void startPreview() { capture = new CameraCapture(); capture.setCapturing(true); capture.start(); Log.i(LOG_TAG, "Starting Socket Camera");

}

public void stopPreview(){ capture.setCapturing(false); Log.i(LOG_TAG, "Stopping Socket Camera"); }

public void setPreviewDisplay(SurfaceHolder surfaceHolder) throws IOException { this.surfaceHolder = surfaceHolder; }

public void setParameters(Camera.Parameters parameters) { //Bit of a hack so the interface looks like that of Log.i(LOG_TAG, "Setting Socket Camera parameters"); parametersCamera.setParameters(parameters); Size size = parameters.getPreviewSize(); bounds = new Rect(0, 0, size.width, size.height); } public Camera.Parameters getParameters() { Log.i(LOG_TAG, "Getting Socket Camera parameters"); return parametersCamera.getParameters(); }

public void release() { Log.i(LOG_TAG, "Releasing Socket Camera parameters"); //TODO need to implement this function }

private class CameraCapture extends Thread {

private boolean capturing = false;

public boolean isCapturing() { return capturing; }

public void setCapturing(boolean capturing) { this.capturing = capturing; }

@Override public void run() { while (capturing) {

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

2 of 17 9/5/2011 1:00 PM

Page 3: Live Camera Preview in the Android Emulator

Canvas c = null; try { c = surfaceHolder.lockCanvas(null); synchronized (surfaceHolder) { Socket socket = null; try { socket = new Socket(); socket.bind(null); socket.setSoTimeout(SOCKET_TIMEOUT); socket.connect(new InetSocketAddress(address, port), SOCKET_TIMEOUT);

//obtain the bitmap InputStream in = socket.getInputStream(); Bitmap bitmap = BitmapFactory.decodeStream(in);

//render it to canvas, scaling if necessary if ( bounds.right == bitmap.getWidth() && bounds.bottom == bitmap.getHeight()) { c.drawBitmap(bitmap, 0, 0, null); } else { Rect dest; if (preserveAspectRatio) { dest = new Rect(bounds); dest.bottom = bitmap.getHeight() * bounds.right / bitmap.getWidth(); dest.offset(0, (bounds.bottom - dest.bottom)/2); } else { dest = bounds; } if (c != null) { c.drawBitmap(bitmap, null, dest, paint); } }

} catch (RuntimeException e) { e.printStackTrace();

} catch (IOException e) { e.printStackTrace(); } finally { try { socket.close(); } catch (IOException e) { /* ignore */ } } } } catch (Exception e) { e.printStackTrace(); } finally {

// do this in a finally so that if an exception is thrown // during the above, we don't leave the Surface in an // inconsistent state if (c != null) { surfaceHolder.unlockCanvasAndPost(c); } } } Log.i(LOG_TAG, "Socket Camera capture stopped"); } }

}

Make sure that you change the ip address to that of your PC.

Now we just need to make a few small modifications to the originalCameraPreview. In this class look for the Preview class that extends the

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

3 of 17 9/5/2011 1:00 PM

Page 4: Live Camera Preview in the Android Emulator

SurfaceView. Now we just need to comments out three lines and replace themwith our own:

class Preview extends SurfaceView implements SurfaceHolder.Callback { SurfaceHolder mHolder; //Camera mCamera; SocketCamera mCamera; Preview(Context context) { super(context);

// Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); //mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); mHolder.setType(SurfaceHolder.SURFACE_TYPE_NORMAL); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, acquire the camera and tell it where // to draw. //mCamera = Camera.open(); mCamera = SocketCamera.open(); try { mCamera.setPreviewDisplay(holder); } catch (IOException exception) { mCamera.release(); mCamera = null; // TODO: add more exception handling logic here } }

Here i've change three lines:

1. Camera mCamera is replaced with SocketCamera mCamera2. mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); isreplaced with mHolder.setType(SurfaceHolder.SURFACE_TYPE_NORMAL);3. mCamera = Camera.open(); is replaced with mCamera =SocketCamera.open();.

So that's it.Now just make sure WebcamBroadcaster is running and start upthe CameraPreview app in the Android emulator, you should now be seeinglive previews in the emulator. Here's a short video of my emulator with thelive preview: (Yes i know, it's me waving a book around)

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

4 of 17 9/5/2011 1:00 PM

Page 5: Live Camera Preview in the Android Emulator

Note: if the WebcamBroadcaster is not picking up your devices you mostprobably have a classpath issue. Make sure that you classpath points to thejmf.jar that is in the same folder as the jmf.properties file. If JMstudio worksok, its very likely that you have a classpath issue.

Oh, one last thing. I also updated the WebCamBroadcaster so that it can beused with YUV format cameras, so here's the code for that as well:

package com.webcambroadcaster;import java.awt.Dimension;import java.awt.image.BufferedImage;import java.io.BufferedOutputStream;import java.io.DataOutputStream;import java.io.IOException;import java.io.OutputStream;import java.net.ServerSocket;import java.net.Socket;import java.util.Vector;

import javax.imageio.ImageIO;import javax.media.Buffer;import javax.media.CannotRealizeException;import javax.media.CaptureDeviceInfo;import javax.media.CaptureDeviceManager;import javax.media.Format;import javax.media.Manager;import javax.media.MediaLocator;import javax.media.NoDataSourceException;import javax.media.NoPlayerException;import javax.media.Player;import javax.media.control.FrameGrabbingControl;import javax.media.format.RGBFormat;import javax.media.format.VideoFormat;import javax.media.format.YUVFormat;import javax.media.protocol.CaptureDevice;import javax.media.protocol.DataSource;import javax.media.util.BufferToImage;

/** * A disposable class that uses JMF to serve a still sequence captured from a * webcam over a socket connection. It doesn't use TCP, it just blindly * captures a still, JPEG compresses it, and pumps it out over any incoming * socket connection. * * @author Tom Gibara * */

public class WebcamBroadcaster {

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

5 of 17 9/5/2011 1:00 PM

Page 6: Live Camera Preview in the Android Emulator

public static boolean RAW = false;

private static Player createPlayer(int width, int height) { try { Vector<CaptureDeviceInfo> devices = CaptureDeviceManager.getDeviceList(null); for (CaptureDeviceInfo info : devices) { DataSource source; Format[] formats = info.getFormats(); for (Format format : formats) { if ((format instanceof RGBFormat)) { RGBFormat rgb = (RGBFormat) format; Dimension size = rgb.getSize(); if (size.width != width || size.height != height) continue; if (rgb.getPixelStride() != 3) continue; if (rgb.getBitsPerPixel() != 24) continue; if ( rgb.getLineStride() != width*3 ) continue; MediaLocator locator = info.getLocator(); source = Manager.createDataSource(locator); source.connect(); System.out.println("RGB Format Found"); ((CaptureDevice)source).getFormatControls()[0].setFormat(rgb); } else if ((format instanceof YUVFormat)) { YUVFormat yuv = (YUVFormat) format; Dimension size = yuv.getSize(); if (size.width != width || size.height != height) continue; MediaLocator locator = info.getLocator(); source = Manager.createDataSource(locator); source.connect(); System.out.println("YUV Format Found"); ((CaptureDevice)source).getFormatControls()[0].setFormat(yuv); } else { continue; }

return Manager.createRealizedPlayer(source); } } } catch (IOException e) { System.out.println(e.toString()); e.printStackTrace(); } catch (NoPlayerException e) { System.out.println(e.toString()); e.printStackTrace(); } catch (CannotRealizeException e) { System.out.println(e.toString()); e.printStackTrace(); } catch (NoDataSourceException e) { System.out.println(e.toString()); e.printStackTrace(); } return null; }

public static void main(String[] args) { int[] values = new int[args.length]; for (int i = 0; i < values.length; i++) { values[i] = Integer.parseInt(args[i]); }

WebcamBroadcaster wb; if (values.length == 0) { wb = new WebcamBroadcaster(); } else if (values.length == 1) { wb = new WebcamBroadcaster(values[0]); } else if (values.length == 2) { wb = new WebcamBroadcaster(values[0], values[1]); } else { wb = new WebcamBroadcaster(values[0], values[1], values[2]); }

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

6 of 17 9/5/2011 1:00 PM

Page 7: Live Camera Preview in the Android Emulator

wb.start(); }

public static final int DEFAULT_PORT = 9889; public static final int DEFAULT_WIDTH = 320; public static final int DEFAULT_HEIGHT = 240;

private final Object lock = new Object();

private final int width; private final int height; private final int port;

private boolean running;

private Player player; private FrameGrabbingControl control; private boolean stopping; private Worker worker;

public WebcamBroadcaster(int width, int height, int port) { this.width = width; this.height = height; this.port = port; }

public WebcamBroadcaster(int width, int height) { this(width, height, DEFAULT_PORT); }

public WebcamBroadcaster(int port) { this(DEFAULT_WIDTH, DEFAULT_HEIGHT, port); }

public WebcamBroadcaster() { this(DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_PORT); }

public void start() { synchronized (lock) { if (running) return; player = createPlayer(width, height); if (player == null) { System.err.println("Unable to find a suitable player"); return; } System.out.println("Starting the player"); player.start(); control = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl"); worker = new Worker(); worker.start(); System.out.println("Grabbing frames"); running = true; } }

public void stop() throws InterruptedException { synchronized (lock) { if (!running) return; if (player != null) { control = null; player.stop(); player = null; } stopping = true; running = false; worker = null; } try { worker.join();

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

7 of 17 9/5/2011 1:00 PM

Page 8: Live Camera Preview in the Android Emulator

} finally { stopping = false; } }

private class Worker extends Thread {

private final int[] data = new int[width*height];

@Override public void run() { ServerSocket ss; try { ss = new ServerSocket(port);

} catch (IOException e) { e.printStackTrace(); return; }

while(true) { FrameGrabbingControl c; synchronized (lock) { if (stopping) break; c = control; } Socket socket = null; try { socket = ss.accept();

Buffer buffer = c.grabFrame(); BufferToImage btoi = new BufferToImage((VideoFormat)buffer.getFormat()); BufferedImage image = (BufferedImage) btoi.createImage(buffer);

if (image != null) { OutputStream out = socket.getOutputStream(); if (RAW) { image.getWritableTile(0, 0).getDataElements(0, 0, width, height, data); image.releaseWritableTile(0, 0); DataOutputStream dout = new DataOutputStream(new BufferedOutputStream(out)); for (int i = 0; i < data.length; i++) { dout.writeInt(data[i]); } dout.close(); } else { ImageIO.write(image, "JPEG", out); } }

socket.close(); socket = null; } catch (IOException e) { e.printStackTrace(); } finally { if (socket != null) try { socket.close(); } catch (IOException e) { /* ignore */ } }

}

try { ss.close(); } catch (IOException e) { /* ignore */ } }

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

8 of 17 9/5/2011 1:00 PM

Page 9: Live Camera Preview in the Android Emulator

Carla said...

10 November 2009 10:07

taf said...

10 November 2009 11:12

benjamin99 said...

20 November 2009 07:16

taf said...

21 November 2009 03:45

}

}

POSTED BY TAF AT 12:42

32 comments:

HiI'm also trying to put to work Tom Gibara's code.But i'm with a problem, i have the latest androidsdk and it keeps giving me the error in theWebcamBroadcaster class in the following lines:

import java.awt.Dimension;import java.awt.image.BufferedImage;andimport javax.imageio.ImageIO;

It seems it cannot resolve this classes.What am i doing wrong?I take a look at my classpath and it is ok, justpointing to jmf.jar.

Could you please help me with is?Thanks

Carla

The WebcamBroadcaster should be run as aSeparate Java application. It is not an Androidapp. It runs on you PC and broadcast framesfrom you web cam over a socket.

The Socket camera class, which is running as Partof the CameraPeview Activity in the emulator willthen pick up the broadcast frames and displaythem in the emulator.

Hi, I had just tried to using live Camera on theemulator. And I had a trouble getting theWebcamBroadcaster work. Here is the errormessage I recieved:

-----------------------------------------------Could not find the main class:WebcamBroadcaster. Program will exit.-----------------------------------------------

Could you please help me with this?Thanks a lot.

Ben

Not a lot for me to go on there Ben. But theWebcamBroadcaster is just a simple Javaapplication, that can be run from the commandline or run in an IDE such as Eclipse. This lookslike a classpath set up issue to me. Have a lookon the web for how to compile and run a basicjava application.

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

9 of 17 9/5/2011 1:00 PM

Page 10: Live Camera Preview in the Android Emulator

Laet said...

9 January 2010 15:16

taf said...

11 January 2010 01:29

andy said...

18 March 2010 19:09

Anonymous said...

12 May 2010 13:08

Hi,I used your example of WebcamBroadcaster, but Ihad some problems. When I execute, it returnsnull when it tries to execute line 49, and thus itstops on line 157, and returns this message:"Unable to find a suitable player".

What am I doing wrong? Could you please helpme with this?

You need to check that you have a device withRGB or YUV Fomat connected to your PC. Oneway.. Go to JMStudio File->preferences, click oncapture devices. If your web cam is not of theseformats you'll have to modify the code as I didfor the YUV format.

Hi,I got my program running but the emulator giveblack screen ..what is the problem?? can any one help me ?

I have the same problem as Laet. I keep gettingthe "Unable to find a suitable player" exception. Itried to detect my device from JMStudio and mywebcam is detected and I can even capture usingthe File menu options in JMFStudio.

Also from the File->Preferences menu, it showsthe following about my device

Name = vfw:Microsoft WDM Image Capture(Win32):0

Locator = vfw://0

Output Formats---->

0. javax.media.format.YUVFormatYUV Video Format: Size =java.awt.Dimension[width=160,height=120]MaxDataLength = 38400 DataType = class [ByuvType = 32 StrideY = 320 StrideUV = 320OffsetY = 0 OffsetU = 1 OffsetV = 3

1. javax.media.format.YUVFormatYUV Video Format: Size =java.awt.Dimension[width=176,height=144]MaxDataLength = 50688 DataType = class [ByuvType = 32 StrideY = 352 StrideUV = 352OffsetY = 0 OffsetU = 1 OffsetV = 3

2. javax.media.format.YUVFormatYUV Video Format: Size =java.awt.Dimension[width=320,height=240]MaxDataLength = 153600 DataType = class [ByuvType = 32 StrideY = 640 StrideUV = 640OffsetY = 0 OffsetU = 1 OffsetV = 3

3. javax.media.format.YUVFormatYUV Video Format: Size =java.awt.Dimension[width=352,height=288]MaxDataLength = 202752 DataType = class [B

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

10 of 17 9/5/2011 1:00 PM

Page 11: Live Camera Preview in the Android Emulator

ugme said...

21 July 2010 23:25

Anonymous said...

8 August 2010 10:01

卡莫 said...

4 September 2010 20:03

Anonymous said...

7 September 2010 06:14

yuvType = 32 StrideY = 704 StrideUV = 704OffsetY = 0 OffsetU = 1 OffsetV = 3

4. javax.media.format.YUVFormatYUV Video Format: Size =java.awt.Dimension[width=640,height=480]MaxDataLength = 614400 DataType = class [ByuvType = 32 StrideY = 1280 StrideUV = 1280OffsetY = 0 OffsetU = 1 OffsetV = 3

Any suggestions?

Hi Andy,

Had same problem of black screen but got itworking.

Check that:1)Your Preview Class has the following (original)methods

public void surfaceDestroyed(SurfaceHolderholder) {mCamera.stopPreview();mCamera = null;}

public void surfaceChanged(SurfaceHolder holder,int format, int w, int h) {Camera.Parameters parameters =mCamera.getParameters();parameters.setPreviewSize(w, h);mCamera.setParameters(parameters);mCamera.startPreview();}

2) Your Manifest File contain CAMERA andINTERNET User permissions.

Don't forget that for the emulator it is necessaryto have a proper internet address. In this case,since you are using the emulator in the samecomputer where the camera is connected to, youhave to use "10.0.2.2" as your address.

Hi, this is awesome .But I have a question, If I want change thewebcam to another entity phone, How should ido it?

Hi, this is a really great job, but the problem isthat I don't know how to make it run xD.Can you help me?? What's the code I need to addto the onCreate Activity method??

Thx.

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

11 of 17 9/5/2011 1:00 PM

Page 12: Live Camera Preview in the Android Emulator

Alejandro said...

6 October 2010 03:46

2e38 said...

10 October 2010 05:50

Regards,

I am working with your code for the emulator torecognize the webcam on my computer and yourcamera to run applications from my computer asLayar. Working from the Eclipse IDE where I havean activity / application with your code andSurfaceWiew SocketCamera (which are 2necessary as I understand).

Emitted from JMF with my cam RGB to IP127.0.0.1 port 8888 which is the IP I set in theprogram.

Not what I'm doing wrong but when running theapplication gives me error:java.lang.RuntimeException andjava.lang.IllegalAccesException.

Anyone can help me? Thanks.

Thanks a lot, it works for me and it's reallyuseful.

I have also written the methods takePicture forSocketCamera. They are on my blog, but it's initalian, so if any english user is interested i pastemethods here. (maybe not the best code but itworks)

// Prova per takePicturepublic final voidtakePicture(Camera.ShutterCallback shutter,Camera.PictureCallback raw,Camera.PictureCallback jpeg) {takePicture(shutter, raw, null, jpeg);}public final voidtakePicture(Camera.ShutterCallback shutter,Camera.PictureCallback raw,Camera.PictureCallback postview,Camera.PictureCallback jpeg) {stopPreview();

try {Socket socket = null;try {socket = new Socket();socket.bind(null);socket.setSoTimeout(SOCKET_TIMEOUT);socket.connect(new InetSocketAddress(address,port), SOCKET_TIMEOUT);

if (shutter != null) shutter.onShutter();

// obtain the bitmapInputStream in = socket.getInputStream();Bitmap bitmap =BitmapFactory.decodeStream(in);ByteArrayOutputStream baos = newByteArrayOutputStream();bitmap.compress(Bitmap.CompressFormat.PNG,100, baos); //bm is the bitmap objectbyte[] b = baos.toByteArray();// Chiama la callbackif (raw != null) raw.onPictureTaken(b, null);if (postview != null) postview.onPictureTaken(b,null);

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

12 of 17 9/5/2011 1:00 PM

Page 13: Live Camera Preview in the Android Emulator

Anonymous said...

18 October 2010 13:40

eray said...

21 October 2010 04:33

Anonymous said...

28 October 2010 14:13

harry said...

3 November 2010 22:13

if (jpeg != null) jpeg.onPictureTaken(b, null);} catch (RuntimeException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {try {socket.close();} catch (IOException e)/* ignore */}}} catch (Exception e) {e.printStackTrace();} finally {}}

@Alejandro: i don't have your problems runningthis code, but :1- If i remember right 127.0.0.1 it's the loopbackaddress of the emulator and if u want to connectto your Computer u must use the explicit ipaddres of computer or 10.0.2.2 (see networkingunder android emulator on android sdk pages)2- IllegalAccesException point me to permissionsof your Code, check the AndroidManifest if uhave added permission for both CAMERA andINTERNET.Elsewhere i can't help, sorry.

hi,exactly which of the files required, do i have toadd the all of others on the tom gibara's page?

hi,very useful work,i'm working on a androidapplication and i need to be able to use mylaptop webcam to go one step forward in myproject..but everytime i run your work i get anerror:

"The application ...(process ...)has stoppedunexpectedly.Please try again."

Can anyone know how to get rid of this error,please someone help me,thanks in andvance

can you post a link to zip project please ?

thanx

hi,i can run the code successfully with any error,however, the webcam image can't be shown inthe emulator. 3 question i would like to ask:

1. how can i ensure the broadcaster is runningsuccessfully? i compile it and it shows thefollowing:

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

13 of 17 9/5/2011 1:00 PM

Page 14: Live Camera Preview in the Android Emulator

Anonymous said...

14 November 2010 11:48

Anonymous said...

14 November 2010 11:56

Anonymous said...

27 November 2010 09:17

Anonymous said...

29 November 2010 06:29

RGB Format FoundStarting the playerGrabbing frames

2. do i need to run the JMStudio before i executethe broadcastor?

3. what IP address in the SocketCamera? i tried10.0.0.2 (my computer's IP), 10.0.2.2 and127.0.0.1, all don't work.

anyone can help? thanks!!

Harry:1.broadcaster is fine(on port 9889)2.no3.i just did ipconfig and set theaddress(192.168.xx.xx) in socketcamera.

Anonymous has left a new comment on yourpost "Live camera preview in the Androidemulator":

Hello Neil,thanks a lot for this post....i got itworking with a Frontech webcam on XP.For the benefit of the readers,apart from thechanges that u hv mentioned above,the followingshould be entered in the manifest file:

uses-permissionandroid:name="android.permission.CAMERA"uses-permissionandroid:name="android.permission.INTERNET"

The first one is reqd when we are doingCamera.open() and the next one for the socketconnection.I had another problem in teh manifest file,thatbeing a mismatch between the activityname,which should be CameraPreview if we aredirectly using your source files.Thanks again...Biswajit Goswami

Hi,I used the same code but it doesn't work for me.the question that I want to ask is:what is the version of sdk that you used to makeit run and also the levelthanks

Hi!

I use ubuntu 10.10 and a Logitech QuickcamExpress. The code is working fine. I just do notget a picture from the camera. I only get blackwith white noise. It's the same in JM studio. Iguess this is a problem with my cam driver, oram i wrong???

Ubuntu 10.10 provides a driver, so i used it. Do i

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

14 of 17 9/5/2011 1:00 PM

Page 15: Live Camera Preview in the Android Emulator

Anonymous said...

29 November 2010 06:50

jcwynford said...

11 January 2011 19:02

Francesca said...

14 January 2011 10:12

Anonymous said...

24 January 2011 21:56

Anonymous said...

4 April 2011 12:03

android said...

have to install an extra driver, or is it anotherproblem.

Hi,I tried to make this code to work but I don't seethe code of Activity to launch the screen soplease can you help methanks

hi, i don't know what's wrong but I was havinghard time getting the emulator detect thecamera.I checked the JMStudio and it worked well, I alsochecked and configured the environment variableclasspath and path but still not working.

what could be the cause of this problem?any help please, thanks. got stocked on this

Hi,I try this code and run wonderfully, thanks.Now, I'd like to create some shape over thecamera view.Can anyone help me?

Hello friends....Can anyone please post all thejava files that are required for using webcam inandroid emulator?...Also, please provide somestep-by-step instructions as to which file shouldgo where....I am working on a Barcode Scannerproject and I am not able to get the emulatorcamera work, so any help is greatlyappreciated......I tried some of the steps here andalso from Tomgibara's site...but I am not able tounderstand which files should go where and whatcode i should include in my Activity.......Also, iam having trouble with the webcambroadcasterfile, which keeps giving me errors, so is manyother files. I followed the steps mentioned below,but i have so many errors when i include the filesin my project......http://stackoverflow.com/questions/1276450/how-to-use-web-camera-in-android-emulator-to-capture-a-live-image.

Please also mention the sdk and jdk versions touse in order to run these files...

Thanks in advance and please try to reply early.

can anyone post the original CameraPreviewclass?It seems a lot of the functions have beendeprecated...........or what r the changes neededin the new file?

Hello friends....Can anyone please post all thejava files that are required for using webcam in

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

15 of 17 9/5/2011 1:00 PM

Page 16: Live Camera Preview in the Android Emulator

30 April 2011 17:18

Talles said...

17 May 2011 06:08

Talles said...

19 May 2011 05:13

Roy said...

8 July 2011 00:03

Toddy said...

18 August 2011 05:17

android emulator?...Also, please provide somestep-by-step instructions as to which file shouldgo where....I am working on a Barcode Scannerproject and I am not able to get the emulatorcamera work, so any help is greatly appreciatedand how can i get the port number pleas any onereply

guy, I get error: java.io.IOException: Could notconnect to capture devicenot connecting in WebcamBroadcaster

if you can help me

Olá amigo,na classe CameraPreview da um erro nogetChildCount e getChildAt do metodo onLayout.pode me ajudar?

Hi ,This is Roy.Your Sensor simulator app is verynice,am very impresed on that.I try to createandroid mobile captured video stream to serverusing RTSP/RTP.I am a android fresher please canu guide me.Mail ID== [email protected] ideas are welcomeThanksRoy

First thanxs 4 ur great work changingTomgibara's code. I have tried to execute both,Webcambroadcaster and SocketCamera. I don'tknow if it's correct, my webcambroadcastershows like someone's above:

RGB Format FoundStarting the playerGrabbing frames

And my socketcamera still shows that chesspicture in instead of my webcam. What am Idoing wrong? I noticed indeedWebcambroadcaster stops on:

socket = ss.accept();

I also create an entry on firewall 4 port 9889.

Thanxs in advance.

Post a Comment

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

16 of 17 9/5/2011 1:00 PM

Page 17: Live Camera Preview in the Android Emulator

Newer Post Older PostHome

Subscribe to: Post Comments (Atom)

Interfuser: Live camera preview in the Android emulator http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emu...

17 of 17 9/5/2011 1:00 PM