Guest User

Untitled

a guest
Aug 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. Is it possible to set a maximum time allowed for android recording using intent?
  2. /**
  3. * Starts a new recording.
  4. */
  5. public void start() throws IOException {
  6.  
  7. recorder = new MediaRecorder();
  8.  
  9. String state = android.os.Environment.getExternalStorageState();
  10.  
  11. if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
  12. throw new IOException("SD Card is not mounted. It is " + state
  13. + ".");
  14. }
  15.  
  16. // make sure the directory we plan to store the recording in exists
  17. File directory = new File(path).getParentFile();
  18. System.out.println("start() directory > " + directory);
  19. if (!directory.exists() && !directory.mkdirs()) {
  20. throw new IOException("Path to file could not be created.");
  21. }
  22.  
  23.  
  24.  
  25. recorder.setAudioSource(MediaRecorder.AudioSource.MIC); // Sets the
  26. // audio source
  27. // to be used
  28. // for recording
  29.  
  30.  
  31.  
  32. recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); // Sets
  33. // the
  34. // format
  35. // of
  36. // the
  37. // output
  38. // file
  39. // produced
  40. // during
  41. // recording.
  42. // 5 Minutes = 300000 Milliseconds
  43.  
  44. recorder.setMaxDuration(300000); // Sets the maximum duration (in ms) of
  45. // the recording session
  46.  
  47.  
  48.  
  49. recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); // Sets the
  50. // audio
  51. // encoder
  52. // to be
  53. // used for
  54. // recording.
  55.  
  56. recorder.setOutputFile(path); // Sets the path of the output file to be
  57. // produced.
  58. recorder.prepare(); // Prepares the recorder to begin capturing and
  59. // encoding data.
  60. recorder.start(); // Recording is now started
  61.  
  62. Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
  63. intent.putExtra("android.intent.extra.durationLimit", 30000);
  64. intent.putExtra("EXTRA_VIDEO_QUALITY", 0);
  65. startActivityForResult(intent, ActivityRequests.REQUEST_TAKE_VIDEO);
Add Comment
Please, Sign In to add comment