I am trying to use the camera's image as part of live wallpaper.
In the Engine that I declared, I have this code:
public class Class extends WallpaperService
{
Camera cam;
@Override
public void onCreate()
{
super.onCreate();
cam = Camera.open();
}
//...
@Override
public Engine onCreateEngine()
{
return new CubeEngine(cam);
}
class CubeEngine extends Engine
{
Camera cam;
CubeEngine(Camera cam)
{
this.cam=cam;
}
//...
@Override
public void onDestroy()
{
if (cam != null)
{
cam.stopPreview();
cam.setPreviewCallback(null);
cam.release();
cam = null;
}
super.onDestroy();
}
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height)
{
try
{
cam.setPreviewDisplay(holder);
cam.startPreview();
}
catch (IOException e)
{
e.printStackTrace();
}
super.onSurfaceChanged(holder, format, width, height);
}
@Override
public void onSurfaceCreated(SurfaceHolder holder)
{
super.onSurfaceCreated(holder);
}
@Override
public void onSurfaceDestroyed(SurfaceHolder holder)
{
if (cam != null)
{
cam.stopPreview();
cam.setPreviewCallback(null);
cam.release();
cam = null;
}
super.onSurfaceDestroyed(holder);
}
//...
}
}
cam is a Camera that was declared as Camera.open();
When I run this I get: java.io.IOException: setPreviewDisplay failed
I am now getting this exception:
07-26 00:12:18.399: WARN/CameraService(1357): Overlay create failed - retrying
07-26 00:12:18.419: WARN/CameraService(1357): Overlay create failed - retrying
07-26 00:12:18.439: WARN/CameraService(1357): Overlay create failed - retrying
07-26 00:12:18.459: WARN/CameraService(1357): Overlay create failed - retrying
07-26 00:12:18.479: WARN/CameraService(1357): Overlay create failed - retrying
07-26 00:12:18.509: WARN/CameraService(1357): Overlay create failed - retrying
07-26 00:12:18.529: WARN/CameraService(1357): Overlay create failed - retrying
07-26 00:12:18.549: WARN/CameraService(1357): Overlay create failed - retrying
07-26 00:12:18.569: ERROR/CameraService(1357): Overlay Creation Failed!
07-26 00:12:18.609: WARN/System.err(4104): java.lang.RuntimeException: startPreview failed
07-26 00:12:18.609: WARN/System.err(4104): at android.hardware.Camera.startPreview(Native Method)
07-26 00:12:18.609: WARN/System.err(4104): at com.petrifiednightmares.transparentphone.main.GenericaCamera.surfaceChanged(GenericaCamera.java:29)
07-26 00:12:18.609: WARN/System.err(4104): at android.service.wallpaper.WallpaperService$Engine.updateSurface(WallpaperService.java:687)
07-26 00:12:18.609: WARN/System.err(4104): at android.service.wallpaper.WallpaperService$Engine.attach(WallpaperService.java:749)
07-26 00:12:18.619: WARN/System.err(4104): at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:984)
07-26 00:12:18.619: WARN/System.err(4104): at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
07-26 00:12:18.619: WARN/System.err(4104): at android.os.Handler.dispatchMessage(Handler.java:99)
07-26 00:12:18.619: WARN/System.err(4104): at android.os.Looper.loop(Looper.java:143)
07-26 00:12:18.619: WARN/System.err(4104): at android.app.ActivityThread.main(ActivityThread.java:4293)
07-26 00:12:18.629: WARN/System.err(4104): at java.lang.reflect.Method.invokeNative(Native Method)
07-26 00:12:18.629: WARN/System.err(4104): at java.lang.reflect.Method.invoke(Method.java:507)
07-26 00:12:18.629: WARN/System.err(4104): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-26 00:12:18.629: WARN/System.err(4104): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-26 00:12:18.629: WARN/System.err(4104): at dalvik.system.NativeStart.main(Native Method)