Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Can';t设置媒体录像机的视频质量_Android_Video_Video Capture - Fatal编程技术网

Android Can';t设置媒体录像机的视频质量

Android Can';t设置媒体录像机的视频质量,android,video,video-capture,Android,Video,Video Capture,在我的代码中,我无法设置camcoder配置文件 private void initRecoreder() { File dir = new File(Environment.getExternalStorageDirectory().getPath() + "/Registrator/Video/"); recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

在我的代码中,我无法设置camcoder配置文件

private void initRecoreder() {
    File dir = new File(Environment.getExternalStorageDirectory().getPath()
            + "/Registrator/Video/");

    recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setMaxDuration(900000);// 15 min
    if (!dir.exists()) {
        dir.mkdirs();
    }
    recorder.setOutputFile(dir.getAbsolutePath() + "video.3gp");
}

private void prepareRecorder() {
    recorder.setPreviewDisplay(holder.getSurface());
    try {
        recorder.prepare();
    } catch (IllegalStateException e) {
        e.printStackTrace();
        finish();
    } catch (IOException e) {
        e.printStackTrace();
        finish();
    }
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    prepareRecorder();
    initRecoreder();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    if (recording) {
        recorder.stop();
        recording = false;
    }
    recorder.release();
    finish();
}
这是我的日志

03-21 11:16:38.660: E/AndroidRuntime(4584): FATAL EXCEPTION: main
03-21 11:16:38.660: E/AndroidRuntime(4584): java.lang.RuntimeException: Unable to start activity ComponentInfo{mobi.esys.videoregistrator/mobi.esys.videoregistrator.RegistatratorActivity}: java.lang.IllegalStateException
03-21 11:16:38.660: E/AndroidRuntime(4584):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at android.os.Looper.loop(Looper.java:137)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at android.app.ActivityThread.main(ActivityThread.java:4507)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at java.lang.reflect.Method.invokeNative(Native Method)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at java.lang.reflect.Method.invoke(Method.java:511)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:978)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at dalvik.system.NativeStart.main(Native Method)
03-21 11:16:38.660: E/AndroidRuntime(4584): Caused by: java.lang.IllegalStateException
03-21 11:16:38.660: E/AndroidRuntime(4584):     at android.media.MediaRecorder.setOutputFormat(Native Method)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at mobi.esys.videoregistrator.RegistatratorActivity.initRecoreder(RegistatratorActivity.java:52)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at mobi.esys.videoregistrator.RegistatratorActivity.onCreate(RegistatratorActivity.java:34)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at android.app.Activity.performCreate(Activity.java:4469)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
03-21 11:16:38.660: E/AndroidRuntime(4584):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
03-21 11:16:38.660: E/AndroidRuntime(4584):     ... 11 more
03-21 11:17:02.930: E/MediaRecorder(4671): setOutputFile called in an invalid state(1)

使用此代码录制视频

       recorder = new MediaRecorder();

          recorder.setCamera(mCamera);
            recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 


            profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);

            recorder.setProfile(profile);

            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            recorder.setOutputFile(path+filename);
            prepareRecorder();
            recorder.start();
并在清单中添加此权限

  <uses-permission android:name="android.permission.CAMERA"></uses-permission>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> 


在onCreate方法中声明上述内容。否,我需要在我的应用程序中指定视频格式、持续时间和质量设置setoutput文件后的持续时间