PSA regarding AVPlayerItem's automaticallyLoadedAssetKeys

For whoever needs to hear this...

Say you have an AVURLAsset:

let asset = AVURLAsset(url: URL(string: "https://www.example.com/playlist.m3u8")!)

Then say you load that asset into an AVPlayerItem, and would like it to automatically load certain asset keys you're interested in ahead of time:

let playerItem = AVPlayerItem(
    asset: avURLAsset,
    automaticallyLoadedAssetKeys: [
        "metadata",
        "commonMetadata",
        "availableMetadataFormats",
        "allMediaSelections",
        "hasProtectedContent",
        "overallDurationHint"])

Among those keys, do not use "tracks" even though it's one of the available options. That will break AirPlay across all platforms (the user chooses an AirPlay destination and the AVPlayerItem's status instantly switches to failed).

Took me far too long to track this down, just wanted to get it out there to save anybody else some time if they ever run into it.

PSA regarding AVPlayerItem's automaticallyLoadedAssetKeys
 
 
Q