我的应用程序读取音频,并在生产者/消费者设置中播放它。使用者线程请求新的样本以呈现给硬件。生产者线程使用AVAssetReader将音频数据从磁盘读取到其缓冲区中。生产者线程在一个循环中运行,检查是否需要读取更多的样本。生产者的缓冲区大小等于4秒的音频。
当我指示我的应用程序缓冲音频时,样本读取成功,没有错误。当我触发我的生产者线程开始渲染音频时,4秒的缓冲区被完美地回放,然后静默。进一步的调查显示,我的资源阅读器在开始播放时失败,因此在初始缓冲之后没有进一步的样本读取:
CMSampleBufferRef ref = [readaudiofile copyNextSampleBuffer];
if (ref == NULL && filereader.status == AVAssetReaderStatusFailed) {
NSLog(@"reader failed: %@", filereader.error);
}
// this produces:
// {NSLocalizedFailureReason=An unknown error occurred (-12785),
// NSUnderlyingError=0x161f60 "The operation couldn’t be completed.
// (OSStatus error -12785.)", NSLocalizedDescription=The operation
// could not be completed}
我的生产者线程代码与函数代码示例MusicLibraryRemoteIODemo相同。我的消费者线程代码是不同的,但我已经逐行比较了几天,似乎找不到问题所在。你知道是什么原因导致AVAssetReader阅读器失败吗?
This post描述了类似的解决方案,并得出结论,音频会话需要正确设置(尽管它没有说明如何设置)。AVAudioSesion配置和AVAssetReader的行为之间是否有联系?
发布于 2011-05-07 02:40:02
我得到了同样的错误,我也在另一个帖子上发布了这个答案
- (void)setupAudio {
[[AVAudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive: YES error:&activationError];
NSLog(@"setupAudio ACTIVATION ERROR IS %@", activationError);
[[AVAudioSession sharedInstance] setPreferredIOBufferDuration:0.1 error:&activationError];
NSLog(@"setupAudio BUFFER DURATION ERROR IS %@", activationError);
}
https://stackoverflow.com/questions/5775548
复制相似问题