StartPreview仅在Galaxy S3上失败

时间:2014-03-04 21:16:45

标签: android android-camera

我们不断收到有关以下堆栈跟踪的StartPreview失败的崩溃报告。在其他设备上运行时,这似乎工作得很好。我尝试使用S3重新编写但不能。它似乎工作得很好。

java.lang.RuntimeException: startPreview failed
at android.hardware.Camera.startPreview(Native Method)
at com.myapp.myservice.photo.PhotoCaptureView.surfaceChanged(PhotoCaptureView.java:293)
at android.view.SurfaceView.updateWindow(SurfaceView.java:621)
at android.view.SurfaceView.access$000(SurfaceView.java:93)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:182)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:864)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2142)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:561)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5455)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)

当预览发生变化时,似乎会发生这种情况。调用startPreview时会发生运行时异常。

public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)  
{  
    if (mCamera == null) {
        Log.w(TAG, "Surface changed but no current camera!");
        return;
    }

    if (mIsPreviewRunning) {
        mCamera.stopPreview();
        mIsPreviewRunning = false;
    }

    try {
        mCamera.setPreviewDisplay(holder);
    } catch (IOException ex) {
        Log.e(TAG, "surfaceChanged: Failed with IOException", ex);
    }

    mCamera.startPreview();
    mIsPreviewRunning = true;
}

非常感谢任何帮助。谢谢!

1 个答案:

答案 0 :(得分:2)

可能是由持有人引起的。在surfaceChanged中,使用SurfaceHolder sHolder = getHolder();检查sHolder是否等于holder。如果不是,请使用mCamera.setPreviewDisplay(sHolder);代替mCamera.setPreviewDisplay(holder);如果sHolder等于持有者。您可以在mCamera.stopPreview();

之前致电mCamera.startPreview();