We are working to move our app from our old in-house HLS download infrastructure to using the new AVAssetDownload APIs and running into issues with downloading additional media characteristics (AVMediaCharacteristicAudible or AVMediaCharacteristicLegible). First pass has been mimicing what theHLS Catalog sample does in terms of fetching that data using this method:
fileprivate func nextMediaSelection(_ asset: AVURLAsset) -> (mediaSelectionGroup: AVMediaSelectionGroup?, mediaSelectionOption: AVMediaSelectionOption?) {
guard let assetCache = asset.assetCache else { return (nil, nil) }
let mediaCharacteristics = [AVMediaCharacteristicAudible, AVMediaCharacteristicLegible]
for mediaCharacteristic in mediaCharacteristics {
if let mediaSelectionGroup = asset.mediaSelectionGroup(forMediaCharacteristic: mediaCharacteristic) {
let savedOptions = assetCache.mediaSelectionOptions(in: mediaSelectionGroup)
if savedOptions.count < mediaSelectionGroup.options.count {
for option in mediaSelectionGroup.options {
if !savedOptions.contains(option) && option.mediaType != AVMediaTypeClosedCaption {
return (mediaSelectionGroup, option)
}
}
}
}
}
What I'm noticing is that audio or subtitle tracks will download multiple times and sometimes just stall. It's as if they are not actually being stored in the AVAssetCache. This happens both in our app as well as the Apple provided sample.
Documentation is a bit hazy on this stuff beyond this HLS Catalog sample, so I feel like I am flying blind here. Any guidance would be welcomed.