-2
myRecorder = new MediaRecorder();
myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myRecorder.setOutputFile(path);

Am using this code to record audio in android. While sending recorded file to web service it throws error because .3gpp format is not allowed. If I send mp3 file it's working.How can I handle it. I surfed for it but couldn't get.

Referred this link: Converting 3gp/amr audio file to mp3 in java

Community
  • 1
  • 1
Vaishu
  • 37
  • 1
  • 7

1 Answers1

2

Well record audio in .mp3 format.

    myRecorder= new MediaRecorder();
    myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    myRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    myRecorder.setOutputFile(path);
uday
  • 1,348
  • 12
  • 27
  • Thanks for the response. I tried this option too. I can able to save in mp3 and play that audio file. The actual problem is am sending the audio file to Web service(ruby paperclip). there "Audio has contents that are not what they are reported to be" am getting response like this. If I send some other mp3 file from my device it's getting uploaded correctly. – Vaishu Aug 25 '15 at 12:27
  • MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.addBinaryBody("audio",data,ContentType.create("audio/mp3"),"test.mp3"); where data is byte[]. by this way am sending data to web service. – Vaishu Aug 25 '15 at 12:29