Is it possible to set a maximum time allowed for a

2019-03-09 01:09发布

I am using the android.provider.MediaStore.ACTION_VIDEO_CAPTURE. I was wondering if there is a way to change the maximum time allowed per recording. I TRIED ADDING Intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,60000);//max of 60 seconds but it continues recording pass that. Thanks in advance.

6条回答
欢心
2楼-- · 2019-03-09 01:16

Actually, MediaStore.EXTRA_DURATION_LIMIT provide time in seconds, NOT in miliseconds! So you just need to change your value from 60000 to 60 ;) Android Documentation

查看更多
欢心
3楼-- · 2019-03-09 01:24
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);

This code works well on API 2.2, but the duration limit does not work on API 2.1

android.intent.extra.durationLimit was introduced in API Level 8, so it's not available in Eclair and earlier, unfortunately. Some device manufacturers may have a proprietary way to set the maximum duration on older devices, which explain why you have seen this working on some pre-Froyo applications.

查看更多
ゆ 、 Hurt°
4楼-- · 2019-03-09 01:29

Use this,here 60 is second Code: intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 60);

查看更多
We Are One
5楼-- · 2019-03-09 01:30

Here's a Kotlin update to launch ACTION_VIDEO_CAPTURE Intent with EXTRA_DURATION_LIMIT set to 60 seconds. As for putExtra(MediaStore.EXTRA_DURATION_LIMIT, 60) is taking in seconds as the value for the duration limit.

val recordVideoIntent = Intent(MediaStore.ACTION_VIDEO_CAPTURE)

recordVideoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 60)
startActivityForResult(recordVideoIntent, INTENT_VIDEO_RECORD_REQUEST)
查看更多
叛逆
6楼-- · 2019-03-09 01:33

Use 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

}

查看更多
Bombasti
7楼-- · 2019-03-09 01:42

For 30 seconds time, try this code.

intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 30);
查看更多
登录 后发表回答