我正在录制来自iphone的音频,如下所示:
//Setup the dictionary object with all the recording settings that this
//Recording sessoin will use
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
//Now that we have our settings we are going to instanciate an instance of our recorder instance.
//Generate a temp file for use by the recording.
NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
NSString *caldate = [now description];
recordedTmpFile = [[NSString stringWithFormat:@"%@/%@.caf", DOCUMENTS_FOLDER, caldate] retain];
NSLog(@"Using File called: %@",recordedTmpFile);
url = [NSURL fileURLWithPath:recordedTmpFile];
error = nil;
//Setup the recorder to use this file and record to it.
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&error];
但我的问题是应用程序,我正在开发的也是为Android开发但使用iPhone和Android的通用服务器。当我将录制的音频从iPhone发布到服务器并尝试在Android中播放该音频时,它会将警报显示为不支持的文件。
我应该记录哪种格式以在iPhone和Android中播放音频?
任何人的帮助都将深受感激。
答案 0 :(得分:1)
它以这种方式为我工作:它的AAC格式适用于两者,但当音频在AAC格式的Android设备上编码时,需要将其放入.m4a的容器中,以使其在ios上播放。它简单地改变了扩展名。
例如:
On android device : morningtune.aac
Now Just change the extension of the song
On ios device : monrningtune.m4a
首先在Android设备上我使用以下参数录制音频
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
现在只需将输出音频的扩展名更改为“m4a”