且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以将压缩的音频文件直接加载到缓冲区中而不进行转换?

更新时间:2023-11-08 13:58:16

要回答我自己的问题,如果所有需要的是精确的音频回放同步,而无需使用音频单元"处理进行自定义处理,那么一定要看一下AVFoundation的 AVPlayer AVAsset

To answer my own question, if all one needs is precise playback-synchronisation of audio, without the custom processing possible using Audio Unit processing, then definitely look at AVFoundation's AVPlayer, AVAsset and AVComposition classes.

虽然此方法看起来更适合于视频播放,但仅使用音频资产,效果很好.这些类使用少量的内存来处理媒体资产(包括CAF,AAC和MP3)的所有加载和缓冲,并且可以使用AVURLAssetPreferPreciseDurationAndTimingKey紧密同步.此外,它具有有用的回调方法,可以将其设置为在播放期间的特定时间调用(用于更新UI等).最后,随着它在Mac(10.7+)上可用,它是通用可可开发的一个很好的解决方案.

Whilst this method looks more suited to video playback, it works perfectly well using only audio assets. These classes handle all the loading and buffering of media assets (including CAF, AAC and MP3), using a tiny amount of memory in doing so, and can be tightly synchronised using the AVURLAssetPreferPreciseDurationAndTimingKey. Also, it has useful callback methods that can be set to invoke at specific times during playback (for updating the UI, amongst other things). Finally, as it became available on Mac (10.7+) it is a good solution for universal Cocoa development.