Ramprasad
Ramprasad

Reputation: 8071

How to save an audio file in mp3 format.Why android does not have this basic support?

How to save an audio file in mp3 format.Why android does not have this basic support?

To save as 3GP:

 mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
 mFileName += "/audiorecordtest.3gp";

 private void startRecording() {
        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mRecorder.setOutputFile(mFileName);
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

        try {
            mRecorder.prepare();
        } catch (IOException e) {
            Log.e(LOG_TAG, "prepare() failed");
        }

        mRecorder.start();
    }
  1. I tried to convert 3gp file to MP3 using Lame,but If want to use Lame,I need NDK.I am trying to convert without using NDK(reference).Is it any possible to way to do this?
  2. Why MediaRecorder.OutputFormat class does not have basic mp3 support in Android?

Upvotes: 1

Views: 4698

Answers (5)

Janusz
Janusz

Reputation: 1

Even if your file created by MediaRecorder has .mp3 name suffix it will be not real mp3. Real MP3 file starts with ID3 tag, not with 0x00..ftyp3gp4'

Upvotes: 0

David
David

Reputation: 1017

(Update)

MP3 is officially supported by android, but only for DEcoding:

http://developer.android.com/guide/appendix/media-formats.html

Core Media Formats: MP3 • Mono/Stereo 8-320Kbps constant (CBR) or variable bit-rate (VBR) MP3 (.mp3)

You can use mpeg4 as an alternative.

You can set it up with:

mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

Upvotes: 0

Akhil Soman
Akhil Soman

Reputation: 2217

Set your outputformat of the recorder to mRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); and the resulting recording will be an mp3 file. I have used this.

Upvotes: 0

Shrish
Shrish

Reputation: 729

1) Trying to convert one encoded format to another without using NDK. The process of converting one form or encoded data to another is called "transcoding". The way transcoding works (as far as i know) is - decode file format A > RAW format > encode raw file to format B. All this is heavy signal processing work and lot of pointer access (..a lot). It is not efficient to do this in java and C/C++ is the best .So you cannot avoid some native NDK calls and cannot avoid using C/C++

2) MP3 format is not a free format. There is company called technicolor (Check: http://mp3licensing.com/mp3/index.html) which controls the licencing for mp3 encoders. Be noted that if you are bringing out a product with mp3 encoders, you have to get licence for them (check the licence agrement) and it is not free. So android being an open source OS cannot give mp3 encoding. You can to use third party encoders. Read the licence agreement from the website i mentioned.

Please correct me if i am wrong.

Regards, Shrish

Upvotes: 0

matiash
matiash

Reputation: 55350

  1. Not that I know of. You don't necessarily have to use the NDK to build Lame yourself, though, you could take a precompiled .so, include it, and just use JNI. Take a look at this project, for example.
  2. If I had to guess, I'd say it's because of patents. But who knows :)

Upvotes: 2

Related Questions