I am working on android app which also supports iOS. I want to record the audio & play it in Android as well as in iOS devices. I am recording audio in android using following settings
MediaRecorder audioRecorder = new MediaRecorder();
audioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
audioRecorder.setAudioSamplingRate(44100);
audioRecorder.setAudioChannels(1);
audioRecorder.setAudioEncodingBitRate(12800);
audioRecorder.setOutputFile(<recordedSoundFilePath>);
audioRecorder.prepare();
audioRecorder.start();
On iOS side , settings are as follows
//audioRecorder is object of AVAudioRecorder
NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] initWithCapacity:10];
NSNumber *formatObject;
formatObject = [NSNumber numberWithInt: kAudioFormatMPEG4AAC ];
[recordSettings setObject:formatObject forKey: AVFormatIDKey];
[recordSettings setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey];
[recordSettings setObject:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
[recordSettings setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey];
[recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSettings setObject:[NSNumber numberWithInt: AVAudioQualityHigh] forKey: AVEncoderAudioQualityKey];
NSURL *soundFileURL = [NSURL fileURLWithPath:[self soundFilePath]];
NSError *error = nil;
audioRecorder = [[ AVAudioRecorder alloc] initWithURL:soundFileURL settings:recordSettings error:&error];
if ([audioRecorder prepareToRecord] == YES){
[audioRecorder record];
}else {
int errorCode = CFSwapInt32HostToBig ([error code]);
NSLog(@"Error: %@ [%4.4s])" , [error localizedDescription], (char*)&errorCode);
}
I can record the audio & it is playing correctly in android devices.
Now the problem is I can play the recorded audio from iOS in Android device , but iOS device can't play the audio recorded on Android device. It returns OSStatus error 1937337955
. I searched about this error , but I can't find anything.
Can anybody tell me what's going wrong in my code ?
Any kind of help is highly appreciated. Thanks in advance.
I faced the same issue in which audio that recorded from Samsung's device is not working on all IOS devices and not even on safari browser. But they working fine in all android devices. I have fixed this issue by adding below lines in AudioRecordingUtil class:
recorder?.let{
it.setAudioSource(MediaRecorder.AudioSource.MIC)
it.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS)
it.setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
}
Hope this can help!
try this one:
audioRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With