Help with LiveWallpaper and Camera

All your problems with Audio, Video and Images.

Help with LiveWallpaper and Camera

Postby pmduque » Sat Nov 20, 2010 7:29 am

Hi,

I'm trying to understand camera development and started with a very simple live wallpaper:

Code: Select all
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 tips?

Thanks
pmduque
Freshman
Freshman
 
Posts: 5
Joined: Tue Nov 16, 2010 2:40 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 13 guests