0

I'm currently recording audio with the following code:

recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
audio_path = getFilename();
recorder.setOutputFile(audio_path);
recorder.prepare();
recorder.start();

It is working, and I can record an audio with the mime type audio/mpeg. But when I send this audio file to server or to an IOS device then they are not able to play this audio. It is working on other android devices. On FireFox it shows error message that No video with supported format or mime type found and on chrome it does also not work. I tried to change the mime type with following code, which I found on This Link:

mRecorder.stop();
mRecorder.release();
String[] paths = {mFileName};
String[] mimeTypes = {"audio/mp3"};
MediaScannerConnection.scanFile(getApplicationContext(),
                                paths,
                                mimeTypes,
                                new MediaScannerConnection.OnScanCompletedListener() {
                                    @Override
                                    public void onScanCompleted(String path, Uri uri) {
                                        System.out.println("SCAN COMPLETED: " + path);

                                    }
                                });

But it is also not changing the mime type of the audio file. How I can set the mime type audio/mp3?

gourav sarswa
  • 325
  • 4
  • 12
  • `and i can record an audio with mime type audio/mpeg.` ?? Where are you setting the mime type in that code? – greenapps Aug 22 '18 at 08:10
  • Strange story. You can set the extension of your audio file with `audio_path` variable. But you cannot set the mime type of a file. Where would it be stored to begin with? – greenapps Aug 22 '18 at 08:13
  • Possible duplicate of [Android : Record sound in mp3 format](https://stackoverflow.com/questions/11985518/android-record-sound-in-mp3-format) – Martin Zeitler Aug 22 '18 at 08:41
  • @greenapps I am not setting mime type any where in my code. I think `recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)` this line set mime type. But i am not sure. – gourav sarswa Aug 22 '18 at 08:55
  • Think that you never should have mentioned mime type. Instead its the audio encoding that is your problem. – greenapps Aug 22 '18 at 09:10

1 Answers1

1

AAC format worked in both iOS and Android set MediaRecorder Encoder to AAC

recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

Check the below link there is multiple answer

Link1

Link2

Jarvis
  • 1,714
  • 2
  • 20
  • 35