Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Is it possible to set a maximum time allowed for android recording using intent?
- /**
- * 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);
Add Comment
Please, Sign In to add comment