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

前端 未结 6 736
天命终不由人
天命终不由人 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:25

    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)
    
    0 讨论(0)
  • 2021-01-31 04:27

    For 30 seconds time, try this code.

    intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 30);
    
    0 讨论(0)
  • 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
    

    }

    0 讨论(0)
  • 2021-01-31 04:46
    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.

    0 讨论(0)
  • 2021-01-31 04:48

    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

    0 讨论(0)
  • 2021-01-31 04:51

    Use this,here 60 is second Code: intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 60);

    0 讨论(0)
提交回复
热议问题