安卓 - 录制视频后停止和重置相机时的致命信号 11



我目前有一个应用程序,我正在尝试录制视频,使用以下方法来初始化相机:

private void initRecorder(Surface surface) throws IOException {
    if (mCamera == null) {
        mCamera = Camera.open();
        mCamera.unlock();
    }
    if (mMediaRecorder == null) mMediaRecorder = new MediaRecorder();
    mMediaRecorder.setPreviewDisplay(surface);
    mMediaRecorder.setCamera(mCamera);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    mMediaRecorder.setVideoEncodingBitRate(512 * 1000);
    mMediaRecorder.setVideoFrameRate(30);
    mMediaRecorder.setVideoSize(640, 480);
    mMediaRecorder.setOutputFile(videoFile);
    try {
        mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    }
    initSuccess = true;
}

当我尝试停止相机或调用surfaceDestroyed时,我调用以下方法:

private void resetCamera()  {
    mMediaRecorder.stop();
    mMediaRecorder.reset();
    mMediaRecorder.release();
    mCamera.release();
    mCamera = null;
    try {
        initRecorder(mHolder.getSurface());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

但是,在此代码中的某个地方,我收到致命信号 11 错误。 显然,代码试图非法访问部分内存。

我想知道,我将如何解决此错误?

以下是从我开始录制视频到停止录制的 Logcat 转储:

D/dalvikvm: GC_FOR_ALLOC freed 1309K, 27% free 7434K/10168K, paused 9ms, total 9ms
I/dalvikvm: Could not compile trace for Ljava/util/Arrays;fill, offset 5
I/dalvikvm: ++++++++++++++++++++++++++++++++++++++++++++
I/dalvikvm: JIT_INFO: ME Issues while compiling trace  Ljava/util/Arrays;fill, offset 5
I/dalvikvm: The trace provoked a spill.
I/dalvikvm: Trying less registerization from 1 to 0
D/dalvikvm: GC_FOR_ALLOC freed 1415K, 27% free 7438K/10168K, paused 10ms, total 10ms
A/libc: Fatal signal 11 (SIGSEGV) at 0x00000010 (code=1), thread 13774 (arch.treadmill3)

在 mMediaRecorder.release() 之后;你必须写 mMediaRecorder = null;因为 release() 方法似乎几乎没有错误。喜欢这个:

if (mMediaRecorder != null) {
        mMediaRecorder.stop();
        mMediaRecorder.reset();
        mMediaRecorder.release();
        mMediaRecorder = null;
    }

相关内容

  • 没有找到相关文章

最新更新