录制视频时出现 RuntimeException [特定于设备]
Posted
技术标签:
【中文标题】录制视频时出现 RuntimeException [特定于设备]【英文标题】:RuntimeException while recording video [Device specific] 【发布时间】:2019-02-26 10:51:48 【问题描述】:我正在尝试从相机录制视频,一切正常,但在 Samsung SM-C7010 中显示错误消息 start failed。
这是我正在使用的。
mMediaRecorder = new MediaRecorder();
// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
// Step 2: Set sources
mMediaRecorder.setAudiosource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
/*CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_720P);
mMediaRecorder.setCaptureRate(profile.videoFrameRate/6.0f);
mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mMediaRecorder.setProfile(profile);*/
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
mMediaRecorder.setProfile(profile);
// Step 4: Set output file
mMediaRecorder.setOutputFile(String.valueOf(camMediaFile));
mMediaRecorder.setMaxDuration(5000);
mMediaRecorder.setCaptureRate(profile.videoFrameRate/6.0f);
mMediaRecorder.setVideoFrameRate(10);
mMediaRecorder.setOrientationHint(videoOrientation);
// Step 5: Set the preview output
mMediaRecorder.setPreviewDisplay(this.getHolder().getSurface());
// Step 6: Prepare configured MediaRecorder
mMediaRecorder.prepare();
mMediaRecorder.start();
删除这两行后一切正常
mMediaRecorder.setCaptureRate(profile.videoFrameRate/6.0f);
mMediaRecorder.setVideoFrameRate(10);
我认为问题出在这两行,但不知道问题出在哪里。
更新(日志文件)
Fatal Exception: java.lang.RuntimeException: start failed.
at android.media.MediaRecorder._start(MediaRecorder.java)
at android.media.MediaRecorder.start(MediaRecorder.java:1170)
at org.octabyte.zeem.Camera.CameraHandler.startGifRecording(CameraHandler.java:484)
at org.octabyte.zeem.Camera.camfrags.Initializer$3.clicked(Initializer.java:230)
at org.octabyte.zeem.Camera.camutil.CameraListener.onClick(CameraListener.java:67)
at org.octabyte.zeem.Camera.helper.OnSwipeTouchListener$GestureListener.onSingleTapUp(OnSwipeTouchListener.java:43)
at android.view.GestureDetector.onTouchEvent(GestureDetector.java:651)
at org.octabyte.zeem.Camera.helper.OnSwipeTouchListener.onTouch(OnSwipeTouchListener.java:27)
at android.view.View.dispatchTouchEvent(View.java:10775)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2886)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2864)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2549)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:605)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1895)
at android.app.Activity.dispatchTouchEvent(Activity.java:3241)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:567)
at android.view.View.dispatchPointerEvent(View.java:11008)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5155)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5007)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4532)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4585)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4551)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4684)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4559)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4741)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4532)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4585)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4551)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4559)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4532)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7092)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7024)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6985)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7202)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
【问题讨论】:
请添加完整的错误日志 请检查更新 ***.com/questions/2859458/… 我在那里检查的内容。这与这个问题完全不同,我已经正确设置了所有内容。唯一的问题在于特定的移动型号。我还提到了问题所在的行,但不知道确切的问题以及如何解决 【参考方案1】:试试这个
mediaRecorder.setCaptureRate(20);
mediaRecorder.setVideoFrameRate(20);
【讨论】:
为什么你都设置了 20 的值?以上是关于录制视频时出现 RuntimeException [特定于设备]的主要内容,如果未能解决你的问题,请参考以下文章
Android 视频录制 java.lang.RuntimeException: start failed.
Camtasia录制时出现video codec open failed错误的解决方法
调用 SQLException.getMessage() 时出现 RuntimeException (DB2)
当spring抛出异常时出现的页面的@ExceptionHandler(RuntimeException.class) 用法