从服务器流式传输.caf音频文件

时间:2013-07-22 11:02:42

标签: ios objective-c audio audio-recording avplayer

我正在开展一个项目,我正在录制语音并将其上传到服务器。上传的文件格式为.caf(核心音频格式)

现在,当我尝试使用AVPLayer从服务器播放此文件时,它会在下面显示错误消息。

Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo=0x2f31e0 {NSLocalizedRecoverySuggestion=Try again later., NSLocalizedDescription=Cannot Complete Action}

我检查了服务器上的文件,但没有损坏。

我的问题是:可以.caf文件支持流式传输吗?如果没有,那么我需要以哪种格式转换我支持流媒体的录制文件?

1 个答案:

答案 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];