AVAssetReader 读取音频,然后失败
我的应用程序读取音频并在生产者/消费者设置中播放它。消费者线程请求新样本渲染到硬件。生产者线程使用 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 阅读器失败吗?
这篇文章描述了类似的解决方案,得出的结论是需要设置音频会话正确地(虽然它没有说明如何)。 AVAudioSesion 配置和 AVAssetReader 的行为之间有任何联系吗?
My app reads audio and plays it back in a producer / consumer setup. The consumer thread requests new samples to render to hardware. The producer thread reads audio data from disk into its buffer using AVAssetReader. The producer thread runs in a loop, checking if more samples need to be read. The producer's buffer size is equal to 4 seconds of audio.
When I instruct my app to buffer audio, samples are read successfully without error. When I trigger my producer thread to begin rendering audio, the 4 second buffer is played back perfectly, then silence. Further investigation reveals that my asset reader fails upon the start of playback, thus no further samples where read after the initial buffering:
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}
My producer thread code is identical to the functional code example MusicLibraryRemoteIODemo. My consumer thread code is different, but I've compared the two line by line for a couple days and can't seem to find the hitch. Any idea what might be causing the AVAssetReader reader to fail?
This post describes similar solutions and it concluded that the Audio Session needed to be set up properly (although it doesn't say how). Is there any connection between AVAudioSesion configuration and the behavior of AVAssetReader?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的错误,我也在另一个线程上发布了这个答案
I was getting this same error, I posted this answer on the other thread as well