AVAssetReader读取audio,然后失败
我的应用程序读取audio并在生产者/消费者设置中播放。 消费者线程请求新的样本呈现给硬件。 生产者线程使用AVAssetReader从磁盘读取audio数据到其缓冲区。 生产者线程循环运行,检查是否需要读取更多的样本。 制作者的缓冲区大小等于4秒的audio。
当我指示我的应用程序缓冲audio,样品读取成功没有错误。 当我触发我的制作者线程开始渲染audio时,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}
我的生产者线程代码与function代码示例MusicLibraryRemoteIODemo完全相同 。 我的消费者线程代码是不同的,但我已经比较了两天一行一行,似乎无法find顺利。 任何想法可能会导致AVAssetReader阅读器失败?
这篇文章描述了类似的解决scheme,并得出结论,audio会议需要设置正确(虽然它没有说明如何)。 AVAudioSesionconfiguration和AVAssetReader的行为之间有任何连接吗?
我得到这个相同的错误,我也发布在另一个线程上的这个答案
- (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); }
- 不logging时隐藏iOS应用程序中的红色录制状态栏
- iOS AudioSessionSetActive()阻塞主线程?
- iOS:Siri不可用不会返回AVAudioSessionInterruptionOptionShouldResume
- 如何解决iOS中的AVCaptureSession v AVAudioSession冲突?
- IOS:在后台播放声音
- 使用AVCaptureAudioDataOutputSampleDelegate无法播放通过语音录制的audio
- 如何使用MPMoviePlayerController播放video时将audio静音/取消静音?
- iOS无video会话播放video
- 如何使MPMoviePlayerController忽略静音开关