在Android 4 / Nexus上使用相机时出错

时间:2012-02-14 03:36:06

标签: android android-camera

当尝试将一些代码移植到Android 4(4.0.3 / Nexus S)时,我们发现了一个 与MediaRecorder有关,我附加了堆栈跟踪。相同 代码在运行Android的同一设备上运行没有任何问题 2.3.x版本。

我会感谢你的想法。

代码:

MediaRecorder testRecorder = new MediaRecorder();

testRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
testRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
testRecorder.setVideoFrameRate(10);
testRecorder.setVideoSize(width, height);
testRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
testRecorder.setPreviewDisplay(recorderHolder.getSurface());

String videoPath    = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ streamer";
testRecorder.setOutputFile(videoPath + "/" + fileName);

try {
    testRecorder.prepare();
} catch (IOException e) {
    e.printStackTrace();
    Log.e("comptest", "Recording of video failed.");
    return false;
}

// start video for one second
testRecorder.start();

堆栈跟踪:

02-14 01:58:44.058: I/MediaRecorderJNI(16719): prepare:
surface=0x1f0dc80 (identity=3717)
02-14 01:58:44.379: E/MediaRecorder(16719): start failed: -19
02-14 01:58:44.386: D/AndroidRuntime(16719): Shutting down VM
02-14 01:58:44.386: W/dalvikvm(16719): threadid=1: thread exiting with
uncaught exception (group=0x40a771f8)
02-14 01:58:44.425: E/AndroidRuntime(16719): FATAL EXCEPTION: main
02-14 01:58:44.425: E/AndroidRuntime(16719):
java.lang.RuntimeException: start failed.
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
android.media.MediaRecorder.start(Native Method)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
de.tu.tk.zap.ui.stream.CameraRecorder.start(CameraRecorder.java:91)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
de.tu.tk.zap.ui.views.record.RecordActivity.startStreaming(RecordActivity.java:
337)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
de.tu.tk.zap.ui.views.record.RecordActivity.surfaceCreated(RecordActivity.java:
287)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
android.view.SurfaceView.updateWindow(SurfaceView.java:533)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
android.view.SurfaceView.access$000(SurfaceView.java:81)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:
590)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1617)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
android.os.Handler.dispatchMessage(Handler.java:99)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
android.os.Looper.loop(Looper.java:137)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
android.app.ActivityThread.main(ActivityThread.java:4424)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
java.lang.reflect.Method.invokeNative(Native Method)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
java.lang.reflect.Method.invoke(Method.java:511)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-14 01:58:44.425: E/AndroidRuntime(16719):    at
dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

我遇到了类似的问题,我不得不改写整个录像机。这似乎是操作系统的问题