2

I am facing the issue in recording the audio for calls . Initially i recorded the audio by using the Mic it records audio but most of the audio is not recorded ,it creates an empty audio file. So that i switched to record the voice calls by using mediaRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL); in this all voice calls are recorded successfully but this VOICE_CALL is supported till kitkat device . Most of them answered record the audio calls through MICROPHONE.

 try {
                    f1 = File.createTempFile("Sound", ".mp3", dir);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                fileName = f1.getName();
                mediaRecorder = new MediaRecorder();
                mediaRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
                mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
                mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
                mediaRecorder.setOutputFile(f1.getAbsolutePath());
                try {
                    mediaRecorder.prepare();
                    mediaRecorder.start();
                } catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                recordstarted = true;

The above is recording through the VOICE_CALLS

The below code is for recording by MIC

try {
                    f1 = File.createTempFile("Sound", ".mp3", dir);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                fileName = f1.getName();
                mediaRecorder = new MediaRecorder();
                mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
                mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
                mediaRecorder.setOutputFile(f1.getAbsolutePath());
                try {
                    mediaRecorder.prepare();
                    mediaRecorder.start();
                } catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                recordstarted = true;

Please help me how to record by MIC. While recording by mic it creates the empty file , when i played that file the error shown as "This type of audio files are not supported".

Prabha Karan
  • 1,309
  • 3
  • 17
  • 35
  • Why are you trying to save an mpeg4 file as a mp3? – Nico Jul 03 '17 at 10:42
  • @ Nico then how could i save the recorded in mp3 file – Prabha Karan Jul 03 '17 at 10:44
  • Can't you set the `MediaRecorder.OutputFormat.MP3`? – Nico Jul 03 '17 at 10:45
  • There is no such format like MediaRecorder.OutputFormat.MP3 – Prabha Karan Jul 03 '17 at 10:46
  • It seems that mp3 encoding is not supported by android. You can use a external library to encode it. Take a look at this [post](https://stackoverflow.com/questions/4886365/androidhow-to-get-media-recorder-output-in-mp3-format) and [this](https://stackoverflow.com/questions/3641920/how-to-encode-a-wav-to-a-mp3-on-a-android-device/) The second post has linked librarys while the first has your solution with a good comment explaining why it isn't working. – Nico Jul 03 '17 at 10:49
  • I searched that mpeg4 format supports the mp3 format – Prabha Karan Jul 03 '17 at 10:52
  • Your player of this file has to be smart enough to detect that this mp3 is not a mp3 file but an aac audio stream inside of a mp4 container. There's a difference as stated by John Smiths comment here: This answer is definitely incorrect. The reason it SEEMS to work is most players are smart enough to figure out that just because the file is called myrecording.mp3, it is actually an .aac encoded audio stream in a .mp4 container. Mp3 is not native in Android (no doubt due to copyright) You are just faking an m4a or an ACC which is NOT mp3. – Nico Jul 03 '17 at 10:53
  • @ Nico see this link https://stackoverflow.com/questions/11985518/android-record-sound-in-mp3-format they recorded by mpeg4 format – Prabha Karan Jul 03 '17 at 10:55
  • And then read this in the post you just send: "As Bruno, and a few others pointed out in the comments, this does not encode the file in MP3. The encoding is still AAC. However, if you try to play a sound, saved using a .mp3 extension via the code above, it will still play without issues because most media players are smart enough to detect the real encoding." It's still just a dirty hack where **the player of the file** has to detect that it is an aac and decode it as such. – Nico Jul 03 '17 at 10:58
  • okk...thats cool, i will try with your answer – Prabha Karan Jul 03 '17 at 11:00

0 Answers0