java.lang.RuntimeException:启动失败

时间:2013-07-18 08:19:23

标签: android camera android-camera

我正在尝试开始录制视频,但程序会在“recorder.start();”行中粉碎。  该计划在华为D1 (8 Mpx)稳定,但在 HTC Desure C (5 Mpx)程序开始出错时

错误:

W/dalvikvm(18833): threadid=1: thread exiting with uncaught exception (group=0x40a8b228)
E/AndroidRuntime(18833): FATAL EXCEPTION: main
E/AndroidRuntime(18833): java.lang.RuntimeException: start failed.

代码:

    public void startRec(SurfaceHolder surfaceHolder, String VideoName) {
        camera.stopPreview();
        camera.unlock();
        recorder.setCamera(camera);
        setRecorderParams();
        recorder.setPreviewDisplay(surfaceHolder.getSurface());      
        recorder.setOutputFile(VideoName);
        try {
            recorder.prepare();
            recorder.start();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void setRecorderParams() {   
        recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
        recorder.setVideoEncodingBitRate(30000);
        recorder.setVideoSize(640, 480);
    }

1 个答案:

答案 0 :(得分:0)

将正确的参数发布到记录器的解决方案。有些设备不提供某些视频编码器或输出格式。

VideoEncoder parameters