Android limit time recording using intent

2019-03-24 17:10发布

How can I limit recording when using intents ? I tryed this code:

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

This part of code works fine when I record video. Time is countdown from 5 to 0 and after 5 seconds recording automatically stop. 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 this time limit 5 seconds does not work when I record sound ?

4条回答
淡お忘
2楼-- · 2019-03-24 17:29
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.

查看更多
Melony?
3楼-- · 2019-03-24 17:34

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;
查看更多
乱世女痞
4楼-- · 2019-03-24 17:35

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

查看更多
我命由我不由天
5楼-- · 2019-03-24 17:39
    intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 60);
查看更多
登录 后发表回答