gpt4 book ai didi

android - StartPreview 仅在 Galaxy S3 上失败

转载 作者:行者123 更新时间:2023-11-29 00:22:32 27 4
gpt4 key购买 nike

我们不断收到 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;
}

任何帮助将不胜感激。谢谢!

最佳答案

可能是holder造成的。在 surfaceChanged 中,使用 SurfaceHolder sHolder = getHolder(); 检查 sHolder 是否等于 holder。如果不是,请使用 mCamera.setPreviewDisplay(sHolder); 而不是 mCamera.setPreviewDisplay(holder); 如果 sHolder 等于 holder。您可以在 mCamera.startPreview();

之前调用 mCamera.stopPreview();

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com