Audio format for iOS and Android Audio format for iOS and Android ios ios

Audio format for iOS and Android


Android and iOS use the same server to storage records. All records are saved without any extension.

When Android downloads a record from the server, my app adds an ".aac" extension.
When using iOS, it adds an ".m4a" extension.

The same record plays good on both mobile platforms.

Record on iOS:

NSDictionary recorderSettings = [[NSDictionary alloc] initWithObjectsAndKeys:                        [NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey,                        [NSNumber numberWithInt:16000],AVSampleRateKey,                        [NSNumber numberWithInt:1],AVNumberOfChannelsKey,                        [NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,                        [NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,                        [NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,                        nil];

For Android:

myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);myRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);myRecorder.setAudioSamplingRate(16000);myRecorder.setAudioChannels(1);mRecorder.setOutputFile(fileName);


We recently completed one app with this kind of functionality recording from both and listening from both iOS and Android, below is code we used for your reference.We relied on our webservice and server for conversion to .mp3 format which can be easily played in both platform.

//iPhone side code. records m4a file format (small in size)NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:                                [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,                                [NSNumber numberWithFloat:16000.0], AVSampleRateKey,                                [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,                                nil];NSError *error = nil;audioRecorder = [[AVAudioRecorder alloc] initWithURL:soundFileURL settings:recordSettings error:&error];if (error)    NSLog(@"error: %@", [error localizedDescription]);else    [audioRecorder prepareToRecord];//Android side code. (records mp4 format and it works straight away by giving mp3 extension.)MediaRecorder recorder = new MediaRecorder();recorder.setAudioSource(MediaRecorder.AudioSource.MIC);recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);recorder.setAudioEncodingBitRate(256);recorder.setAudioChannels(1);recorder.setAudioSamplingRate(44100);recorder.setOutputFile(getFilename());try {    recorder.prepare();    recorder.start();    myCount=new MyCount(thirtysec, onesecond);    myCount.start();    recordingDone=true;    count=0;    handler.sendEmptyMessage(0);    if(progressDialog.isShowing())        progressDialog.dismiss();} catch (IllegalStateException e) {    e.printStackTrace();    StringWriter strTrace = new StringWriter();    e.printStackTrace(new PrintWriter(strTrace));    CrashReportActivity.appendLog(                                  "\nEXCEPTION : \n" + strTrace.toString() + "\n",                                  Comment.this);} catch (IOException e) {    e.printStackTrace();    StringWriter strTrace = new StringWriter();    e.printStackTrace(new PrintWriter(strTrace));    CrashReportActivity.appendLog(                                  "\nEXCEPTION : \n" + strTrace.toString() + "\n",                                  Comment.this);}

You can find out conversion code from m4a to mp3 in .Net easily, look around by googling (lame or faad some utility like that).

Hope this helps.


We recently faced this interoperability issue. We were trying to record a file in aac format in both platforms but the files recorded using Samsung handsets were not played in iOS. So we had to use both 3gp as well as aac formats in order to play the file across multiple devices in android and ios.

Following is the code that we used when recording a file in Android:

    mRecorder = new MediaRecorder();    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);    mRecorder.setOutputFile(fileName);

We kept the extension of the recorded file as .3gp.

In iOS, however the recording can not be performed in 3gp so we recorded file in .aac in iOS which can be played in both the platforms.