是否可以使用intent设置允许Android录制的最长时间?

use*_*139 26 video android android-intent

我正在使用android.provider.MediaStore.ACTION_VIDEO_CAPTURE.我想知道是否有办法改变每次录制允许的最长时间.我试过添加, Intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,60000);//max of 60 seconds 但它继续记录传递.提前致谢.

小智 33

实际上,MediaStore.EXTRA_DURATION_LIMIT单位提供时间,而不是以毫秒为单位!所以你只需要将你的值从60000改为60;) Android文档


jen*_*fer 17

Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra("android.intent.extra.durationLimit", 30000);
intent.putExtra("EXTRA_VIDEO_QUALITY", 0);
startActivityForResult(intent, ActivityRequests.REQUEST_TAKE_VIDEO);
Run Code Online (Sandbox Code Playgroud)

此代码适用于API 2.2,但持续时间限制不适用于API 2.1

android.intent.extra.durationLimitAPI Level 8,不幸的是,它被介绍在Eclair和更早的版本中.某些设备制造商可能采用专有方法设置旧设备的最大持续时间,这可以解释为什么您已经看到这种方法可用于某些Froyo之前的应用程序.

  • 这里的3000表示50分钟,因为durationLimit以秒为单位而不是毫秒 (2认同)

Par*_*ani 16

30秒时间,请尝试此代码.

intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 30);
Run Code Online (Sandbox Code Playgroud)


jen*_*fer 2

使用MediaRecorder

 /**
     * Starts a new recording.
     */
    public void start() throws IOException {

    recorder = new MediaRecorder();

    String state = android.os.Environment.getExternalStorageState();

    if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
        throw new IOException("SD Card is not mounted.  It is " + state
            + ".");
    }

    // make sure the directory we plan to store the recording in exists
    File directory = new File(path).getParentFile();
    System.out.println("start() directory >  " + directory);
    if (!directory.exists() && !directory.mkdirs()) {
        throw new IOException("Path to file could not be created.");
    }



    recorder.setAudioSource(MediaRecorder.AudioSource.MIC); // Sets the
    // audio source
    // to be used
    // for recording



    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); // Sets
    // the
    // format
    // of
    // the
    // output
    // file
    // produced
    // during
    // recording.
    // 5 Minutes = 300000 Milliseconds

    recorder.setMaxDuration(300000); // Sets the maximum duration (in ms) of
    // the recording session



    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); // Sets the
    // audio
    // encoder
    // to be
    // used for
    // recording.

    recorder.setOutputFile(path); // Sets the path of the output file to be
    // produced.
    recorder.prepare(); // Prepares the recorder to begin capturing and
    // encoding data.
    recorder.start(); // Recording is now started
Run Code Online (Sandbox Code Playgroud)

}