RecordVideo:java.lang.RuntimeException:启动失败

时间:2012-11-25 10:17:11

标签: android video-recording

我在使用android 4.1.2对nexus进行视频重新编码时出现问题。

 private static final String OUTPUT_FILE="/storage/sdcard0/uatestvideo1.mp4";

Android Manifest:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.RECORD_VIDEO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.STORAGE" />
<uses-feature android:name="android.hardware.camra"/>

onCreate:在oncreate中我有: ...

final SurfaceHolder holder =    videoView.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

...

private void beginRecording(SurfaceHolder holder) throws Exception{

        if(recorder!=null){
            recorder.stop();
            recorder.release();
            recorder=null;
        }
        File outFile = new File(OUTPUT_FILE);
        if(outFile.exists()){
            outFile.delete();
        }

        try{
            recorder = new MediaRecorder();
            recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
            recorder.setVideoSize(320, 240);
            recorder.setVideoFrameRate(15);
            recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
            recorder.setMaxDuration(200000);
            recorder.setPreviewDisplay(holder.getSurface());
            recorder.setOutputFile(OUTPUT_FILE);
            recorder.prepare();
                recorder.start();
        }catch(Exception e){
            Log.e(TAG, e.toString());
            e.printStackTrace();
        }

    }


}

错误:

11-25 10:46:07.723: E/MediaRecorder(15354): start failed: -19
11-25 10:46:07.727: E/RecordVideo(15354): java.lang.RuntimeException: start failed.
11-25 10:46:07.727: D/Blad w rekorder(15354): java.lang.RuntimeException: start failed.
11-25 10:46:07.727: W/System.err(15354): java.lang.RuntimeException: start failed.
11-25 10:46:07.727: W/System.err(15354):    at android.media.MediaRecorder.start(Native Method)
11-25 10:46:07.727: W/System.err(15354):    at com.plym.andr.UsVideoRecorder.beginRecording(UsVideoRecorder.java:198)
11-25 10:46:07.727: W/System.err(15354):    at com.plym.andr.UsVideoRecorder.access$2(UsVideoRecorder.java:168)
11-25 10:46:07.727: W/System.err(15354):    at com.plym.andr.UsVideoRecorder$1.onClick(UsVideoRecorder.java:76)
11-25 10:46:07.727: W/System.err(15354):    at android.view.View.performClick(View.java:4084)
11-25 10:46:07.727: W/System.err(15354):    at android.view.View$PerformClick.run(View.java:16966)
11-25 10:46:07.731: W/System.err(15354):    at android.os.Handler.handleCallback(Handler.java:615)
11-25 10:46:07.731: W/System.err(15354):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-25 10:46:07.731: W/System.err(15354):    at android.os.Looper.loop(Looper.java:137)
11-25 10:46:07.731: W/System.err(15354):    at android.app.ActivityThread.main(ActivityThread.java:4745)
11-25 10:46:07.731: W/System.err(15354):    at java.lang.reflect.Method.invokeNative(Native Method)
11-25 10:46:07.731: W/System.err(15354):    at java.lang.reflect.Method.invoke(Method.java:511)
11-25 10:46:07.731: W/System.err(15354):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-25 10:46:07.731: W/System.err(15354):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-25 10:46:07.731: W/System.err(15354):    at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:2)

-19NO_INIT的错误。这意味着您的recorder未正确初始化。

检查this link是否有类似的问题。