我正在开展一个项目,我正在录制语音并将其上传到服务器。上传的文件格式为.caf(核心音频格式)
现在,当我尝试使用AVPLayer
从服务器播放此文件时,它会在下面显示错误消息。
Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo=0x2f31e0 {NSLocalizedRecoverySuggestion=Try again later., NSLocalizedDescription=Cannot Complete Action}
我检查了服务器上的文件,但没有损坏。
我的问题是:可以.caf文件支持流式传输吗?如果没有,那么我需要以哪种格式转换我支持流媒体的录制文件?
答案 0 :(得分:2)
在AVAudioSession
使用.mp4双方播放音频:
AVAudioSession * audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &error];
[audioSession setActive:YES error: &error];
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
NSURL *recordedTmpFile = [NSURL fileURLWithPath:yourdirectorypath];
//file=[NSString stringWithFormat:@"%@",recordedTmpFile];
NSLog(@" filr url%@",recordedTmpFile);
// NSLog(@" filr url%@",file);
recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];