Question

With my app you can record short audio comments.

    final MediaRecorder recorder = new MediaRecorder();
    recorder.setMaxDuration(300000);
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    final String path = getOutputAudioFilePath(activity);
    recorder.setOutputFile(path);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    try {
        recorder.prepare();
    } catch (IOException e) {
        Toast.makeText(activity,e.getMessage(),Toast.LENGTH_LONG).show();
    }
    recorder.start();

The app launches "java.lang.RuntimeException: setMaxDuration failed." with a Galaxy S. I have tested this function in many devices and they don't launch this exception. Obviously I have the following permission in the xml Manifest

<uses-permission android:name="android.permission.RECORD_AUDIO" />

What is the problem?

Was it helpful?

Solution

The documentation says:

Sets the maximum duration (in ms) of the recording session. Call this after setOutFormat() but before prepare(). After recording reaches the specified duration, a notification will be sent to the MediaRecorder.OnInfoListener with a "what" code of MEDIA_RECORDER_INFO_MAX_DURATION_REACHED and recording will be stopped. Stopping happens asynchronously, there is no guarantee that the recorder will have stopped by the time the listener is notified.

You set the max duration before you set the outputFormat.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top