Issue getting camera emulation to work with Tom G's HttpCamera

Posted by user591524 on Stack Overflow See other posts from Stack Overflow or by user591524
Published on 2011-01-28T23:22:43Z Indexed on 2011/01/28 23:25 UTC
Read the original article Hit count: 304

Filed under:
|
|
|

I am trying to use the android emulator to preview video from webcam. I have used the tom gibara sample code, minus the webbroadcaster (i am instead using VLC streaming via http).

So, I have modified the SDK's "CameraPreview" app to use the HttpCamera, but the stream never appears. Debugging through doesn't give me any clues either. I wonder if anything obvious is clear to others? The preview app launches and remains black.

Notes: 1) I have updated the original CameraPreview class as described here: http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emulator.html, but referencing httpCamera instead of socketcamera. 2) I updated Tom's original example to reference "Camera" type instead of deprecated "CameraDevice" type. 3) Below is my CameraPreview.java. 4) THANK YOU

package com.example.android.apis.graphics;

import android.app.Activity; import android.content.Context; import android.hardware.Camera; import android.os.Bundle; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.Window; import java.io.IOException; import android.graphics.Canvas;

// ----------------------------------------------------------------------

public class CameraPreview extends Activity {
private Preview mPreview;

@Override

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

    // Hide the window title.
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    // Create our Preview view and set it as the content of our activity.
    mPreview = new Preview(this);
    setContentView(mPreview);
}

}

// ----------------------------------------------------------------------

class Preview extends SurfaceView implements SurfaceHolder.Callback { SurfaceHolder mHolder; //Camera mCamera; HttpCamera mCamera;//changed

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);//changed
}

public void surfaceCreated(SurfaceHolder holder) {
    // The Surface has been created, acquire the camera and tell it where
    // to draw.
    //mCamera = Camera.open();
 this.StartCameraPreview(holder);
}

public void surfaceDestroyed(SurfaceHolder holder) {
    // Surface will be destroyed when we return, so stop the preview.
    // Because the CameraDevice object is not a shared resource, it's very
    // important to release it when the activity is paused.
    //mCamera.stopPreview();//changed
    mCamera = null;
}

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    // Now that the size is known, set up the camera parameters and begin
    // the preview.
    //Camera.Parameters parameters = mCamera.getParameters();
    //parameters.setPreviewSize(w, h);
    //mCamera.setParameters(parameters);
    //mCamera.startPreview();
 this.StartCameraPreview(holder);
}

private void StartCameraPreview(SurfaceHolder sh)
{
 mCamera = new HttpCamera("10.213.74.247:443", 640, 480, true);//changed

    try {
       //mCamera.setPreviewDisplay(holder);
     Canvas c = sh.lockCanvas(null);
     mCamera.capture(c);
     sh.unlockCanvasAndPost(c);

    } catch (Exception exception) {
        //mCamera.release();
        mCamera = null;
        // TODO: add more exception handling logic here
    }
}

}

© Stack Overflow or respective owner

Related posts about android

Related posts about streaming