Hi,
I'm trying to understand camera development and started with a very simple
live wallpaper:
package com.example.LiveCamera;
import java.io.IOException;
import android.hardware.Camera;
import android.service.wallpaper.WallpaperService;
import android.util.Log;
import android.view.SurfaceHolder;
public class LiveCamera extends WallpaperService {
@Override
public Engine onCreateEngine() {
android.os.Debug.waitForDebugger();
return new LiveCameraEngine();
}
public class LiveCameraEngine extends Engine {
private Camera mCamera;
LiveCameraEngine() {
android.os.Debug.waitForDebugger();
}
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
super.onSurfaceCreated(holder);
this.mCamera = Camera.open();
try {
this.mCamera.setPreviewDisplay(holder);
} catch (IOException e) {
Log.d("onSurfaceCreated","Error in
Camera.setPreviewDisplay"+e);
}
}
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int
w, int h) {
final Camera.Parameters parameters =
this.mCamera.getParameters();
parameters.setPreviewSize(w, h);
this.mCamera.setParameters(parameters);
this.mCamera.startPreview();
}
@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(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();
mCamera.release();
mCamera = null;
}
}
}
I always get this runtime error on the Camera.startPreview:
11-20 06:18:52.543: ERROR/AndroidRuntime(2054): java.lang.RuntimeException:
startPreview failed
11-20 06:18:52.543: ERROR/AndroidRuntime(2054): at
android.hardware.Camera.startPreview(Native Method)
11-20 06:18:52.543: ERROR/AndroidRuntime(2054): at
com.example.LiveCamera.LiveCamera$LiveCameraEngine.onSurfaceChanged(LiveCamera.java:46)
11-20 06:18:52.543: ERROR/AndroidRuntime(2054): at
android.service.wallpaper.WallpaperService$Engine.updateSurface(WallpaperService.java:566)
...
Is this related to be using it with a LiveWallpaper? I'm using android-7 as
target and I get the same error in the phone (Samsung Galaxy S) and on the
Emulator...
Any idea on what the error might be?
Thanks
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en