Search code examples
iosaudioavfoundationnsdocumentdirectoryxcasset

Store iOS app audio files app in xcassets or documents directory?


If an app requires hundreds of audio files (they're small, 5-25KB), is it better to put them in an asset catalog or the documents directory? I've tried both approaches and they don't seem much different, it's a pain to manage hundreds of files in the project navigator either way and it's the same app filesize for both.


Solution

  • So far, I've found one thing that influences whether to "just" put audio files in the app bundle or to put it in the asset catalog portion of the app bundle.

    When you put audio files in the asset catalog, it's available as data, there's no URL. As I understand it now, if you want a URL, you'll have to extract the data and create a file, which is double work.

    When you have a URL that's available automatically when you "just" put audio files in the app bundle, it gives you more options. Like using AVQueuePlayer with AVPlayerItem. AVPlayerItem only takes a URL, not data. If you wanted to play audio files one after another from the asset catalog, it's more work, you have to write code for AVAudioPlayerDelegate, whereas with AVQueuePlayer, you just provide an array of AVPlayerItems.

    I suspect that there may be more advantages having a URL to reference and am not seeing the advantages the asset catalog has yet, so my opinion is subject to change.