Is it possible to set a maximum time allowed for android recording using intent?

前端 未结 6 734
天命终不由人
天命终不由人 2021-01-31 03:44

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

6条回答
  •  无人及你
    2021-01-31 04:36

    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
    

    }

提交回复
热议问题