How to limit audio recording time using Intent?

mira picture mira · Mar 22, 2013 · Viewed 9.8k times · Source

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?

Answer

sns picture sns · Dec 29, 2014

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;