【问题标题】:AVAssetReader reads audio, then failsAVAssetReader 读取音频,然后失败
【发布时间】:2011-04-25 05:37:14
【问题描述】:

我的应用读取音频并在生产者/消费者设置中播放。消费者线程请求新样本以呈现给硬件。生产者线程使用 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 的行为之间有什么联系吗?

【问题讨论】:

    标签: objective-c ios core-audio avfoundation avaudiosession


    【解决方案1】:

    我遇到了同样的错误,我也在另一个帖子上发布了这个答案

    - (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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-21
      • 1970-01-01
      • 2013-04-23
      • 2016-09-06
      相关资源
      最近更新 更多