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
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)
For 30 seconds time, try this code.
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 30);
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
}
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.
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
Use this,here 60 is second Code: intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 60);