How to save audio recording with PlaybackParams in Android?-ThrowExceptions

Exception or error:

I am working on an audio recorder app which has some effects. I am getting a problem that I cannot save audio files with effects. As soon as I stop recording it saves recording. But I want to save the recording when I click on the Save button with effects. I am using Seekbar for changing pitch.

Note: I am using AudioRecorder to record audio and AudioPLayer to play recorded audio and PlaybackParams for effects.

Code for MediaRecorder

mediaRecorder=new MediaRecorder(); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);             
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);             
mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);             
mediaRecorder.setOutputFile(mFileName);

If I try to remove setOutputFile than the app crash.

Here is code for PlayRecording

mediaPlayer = new MediaPlayer();
    try {
        mediaPlayer.setDataSource(AudioSavePathInDevice);
        mediaPlayer.prepare();
    } catch (IOException e) {
        e.printStackTrace();
    }

    params.setPitch(0.5f);
    mediaPlayer.setPlaybackParams(params);
    mediaPlayer.start();

    Toast.makeText(MainActivity.this, "Recording Playing",
            Toast.LENGTH_LONG).show();

}

I am able to play it with the effect but unable to save it. Any Ideas how can I save recording with effects??

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *