我们不断收到崩溃报告,其中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;
}


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

最佳答案

可能是持有人造成的。在surfaceChanged中,使用SurfaceHolder sHolder = getHolder();检查sHolder是否等于holder。如果不是,请使用mCamera.setPreviewDisplay(sHolder);代替mCamera.setPreviewDisplay(holder);如果sHolder等于holder。您可以在mCamera.stopPreview();之前致电mCamera.startPreview();

关于android - StartPreview仅在Galaxy S3上失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22183226/

10-09 21:03