Mediarecorder开始失败-19

时间:2012-06-28 17:10:12

标签: android mediarecorder

我在为mediarecorder运行start()时收到此错误。

06-28 18:46:22.570: E/MediaRecorder(9540): start failed: -19
06-28 18:46:22.570: W/System.err(9540): java.lang.RuntimeException: start failed.

我正在扩展mediarecorder类 我的代码:

camera = Camera.open(cameraId);
super.setCamera(camera);
        super.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        super.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
        if (mode==MODE_DEFAULT) {
            super.setMaxDuration(1000);
            super.setMaxFileSize(Integer.MAX_VALUE);
        } else {
            // On some phones a RuntimeException might be thrown :/
            try {
                super.setMaxDuration(0);
                super.setMaxFileSize(Integer.MAX_VALUE); 
            } catch (RuntimeException e) {
                Log.e(TAG,"setMaxDuration or setMaxFileSize failed !");
            }
        }
        super.setVideoEncoder(videoEncoder);
        if(surfaceHolder!=null)
        super.setPreviewDisplay(surfaceHolder.getSurface());
        //super.setVideoSize(quality.resX,quality.resY);
        super.setVideoFrameRate(quality.frameRate);
        super.setVideoEncodingBitRate(quality.bitRate);

我看到了这些页面  Error opening android camera for streaming video
 Android MediaRecorder - "start failed: -19"
但是他们没有为我工作...... 在archos 80 g9,android 3.2上运行 有人有任何想法吗?

5 个答案:

答案 0 :(得分:4)

通过删除修复

super.setVideoFrameRate(quality.frameRate);

答案 1 :(得分:3)

我在视频录制过程中遇到了同样的问题,我通过添加视频录制来解决这个问题

/**
 * Start video recording by cleaning the old camera preview
 */
private void startVideoRecorder() {
    // THIS IS NEEDED BECAUSE THE GLASS CURRENTLY THROWS AN ERROR OF
    // "MediaRecorder start failed: -19"
    // THIS WONT BE NEEDED INCASE OF PHONE AND TABLET
    // This causes crash in glass kitkat version so remove it
    // try {
    // mCamera.setPreviewDisplay(null);
    // } catch (java.io.IOException ioe) {
    // Log.d(TAG,
    // "IOException nullifying preview display: "
    // + ioe.getMessage());
    // }
    // mCamera.stopPreview();
    // mCamera.unlock();
    recorder = new MediaRecorder();
    // Let's initRecorder so we can record again
    initRecorder();
}

/**
 * Initialize video recorder to record video
 */
private void initRecorder() {
    try {
        File dir = new File(folderPath);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        mCamera.stopPreview();
        mCamera.unlock();
        videofile = new File(dir, fileName + ".mp4");
        recorder.setCamera(mCamera);

        // Step 2: Set sources
        recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

        // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
        recorder.setProfile(CamcorderProfile
                .get(CamcorderProfile.QUALITY_HIGH));

        // Step 4: Set output file
        recorder.setOutputFile(videofile.getAbsolutePath());
        // Step 5: Set the preview output
        recorder.setPreviewDisplay(mPreview.getHolder().getSurface());
        // Step 6: Prepare configured MediaRecorder
        recorder.setMaxDuration(video_duration * 1000);
        recorder.setOnInfoListener(new OnInfoListener() {

            @Override
            public void onInfo(MediaRecorder mr, int what, int extra) {
                if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {

                    mCamera.stopPreview();
                    releaseMediaRecorder();

                    /*
                     * initiate media scan and put the new things into the
                     * path array to make the scanner aware of the location
                     * and the files you want to see
                     */MediaScannerConnection.scanFile(
                            CuxtomCamActivity.this,
                            new String[] { videofile.getPath() }, null,
                            null);

                    Intent intent = new Intent();
                    intent.putExtra(CuxtomIntent.FILE_PATH,
                            videofile.getPath());
                    intent.putExtra(CuxtomIntent.FILE_TYPE, FILE_TYPE.VIDEO);
                    setResult(RESULT_OK, intent);
                    finish();
                }

            }
        });
        recorder.prepare();
        recorder.start();
    } catch (Exception e) {
        Log.e("Error Stating CuXtom Camera", e.getMessage());
    }
}
private void releaseMediaRecorder() {
    if (recorder != null) {
        recorder.reset(); // clear recorder configuration
        recorder.release(); // release the recorder object
        recorder = null;
    }
}

要查看相机实际实现方式的详细信息,请参阅Open Source Cuxtom Cam

答案 2 :(得分:1)

我在MediaRecorder.start()方法的文档中发现了一个微妙的提示,表明在尝试重新录制之前它是否无法锁定({} Camera。这对我有用。意味着在API级别13之后修复了Camera状态错误 - 调用Camera.lock()是已知的解决方法。

答案 3 :(得分:0)

此代码适用于我(找到here

mCamera.unlock(); // maybe not for your activity flow

//1st. Initial state
mProfile = CamcorderProfile.get( CamcorderProfile.QUALITY_HIGH );
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setCamera( mCamera );

//2nd. Initialized state
mMediaRecorder.setAudioSource( MediaRecorder.AudioSource.CAMCORDER );
mMediaRecorder.setVideoSource( MediaRecorder.VideoSource.CAMERA );

//3rd. config
mMediaRecorder.setOutputFormat( mProfile.fileFormat );
mMediaRecorder.setAudioEncoder( mProfile.audioCodec );
mMediaRecorder.setVideoEncoder( mProfile.videoCodec );
mMediaRecorder.setOutputFile( "/sdcard/FBVideo.3gp" );
mMediaRecorder.setVideoSize( mProfile.videoFrameWidth, mProfile.videoFrameHeight );
mMediaRecorder.setVideoFrameRate( mProfile.videoFrameRate );
mMediaRecorder.setVideoEncodingBitRate( mProfile.videoBitRate );
mMediaRecorder.setAudioEncodingBitRate( mProfile.audioBitRate );
mMediaRecorder.setAudioChannels( mProfile.audioChannels );
mMediaRecorder.setAudioSamplingRate( mProfile.audioSampleRate );
mMediaRecorder.setPreviewDisplay( mHolder.getSurface() );

try {
    mMediaRecorder.prepare();
    mMediaRecorder.start();
} catch ( IllegalStateException e ) {
    e.printStackTrace();
} catch ( IOException e ) {
    e.printStackTrace();
}

答案 4 :(得分:0)

这里的问题与camera有关。只需使用camera.unlock()允许媒体进程访问摄像机。

必须在调用MediaRecorder.setCamera(Camera)之前完成此操作。录制开始后无法调用。

了解更多here

相关问题