How to limit audio recording time using Intent?
Asked Answered
C

4

16

How can I limit recording when using intents?

I tried this code:

 Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
 intent.putExtra("android.intent.extra.durationLimit",5);    
 startActivityForResult(intent,RQS_RECORDING);

This code works fine when I record video. Time is countdown from 5 to 0 and after 5 seconds recording automatically stops. But this limited time does not work when I record sound. Why?

Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
intent.putExtra("android.intent.extra.durationLimit", 5);
startActivityForResult(intent, RQS_RECORDING);

Why does this 5-second time limit not work when I record sound?

Cockboat answered 22/3, 2013 at 9:58 Comment(1)
I'm afraid havent got an answer. It seems sollution does not exist :-)Cockboat
K
10

I Have a similar problem and I fixed my problem using below code snippet:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 5);
startActivityForResult(this, cameraIntent,CAMERA_PIC_REQUEST);

where CAMERA_PIC_REQUEST is my int type as:

private static final int CAMERA_PIC_REQUEST = 1337;
Keelboat answered 29/12, 2014 at 17:45 Comment(2)
Thank you! cameraIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 5); totally worked for me. :) Although I changed the number to 60, for 60 seconds.Gambill
Hi, For me, it works for video. For audio I used this https://mcmap.net/q/750989/-how-to-limit-native-voice-recorder-at-certain-time-period-and-sizeMyriagram
N
2

you should be try with MediaRecorder mRecorder = new MediaRecorder(); and mRecorder.setMaxDuration(5000) // 5 seconds;

Neodarwinism answered 20/6, 2013 at 6:1 Comment(0)
T
1
private void recordVideo() {
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);

// set video quality
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 30);

intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set Video file
startActivityForResult(intent, CAMERA_CAPTURE_VIDEO_REQUEST_CODE);
}

fileuri is your filepath. Try this.

Thenceforward answered 13/7, 2015 at 6:10 Comment(0)
G
0
    intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 60);
Gummite answered 13/3, 2014 at 10:1 Comment(1)
MediaStore.EXTRA_DURATION_LIMIT is exactly the same thing of "android.intent.extra.durationLimit"Society

© 2022 - 2024 — McMap. All rights reserved.