Reputation: 8071
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();
}
Upvotes: 1
Views: 4698
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
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
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
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
Reputation: 55350
Upvotes: 2