Inconsistent HLS Download Caching Behavior

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.

Post not yet marked as solved Up vote post of justinwme Down vote post of justinwme
3.3k views

Replies

I am also having both of these problems.


Retry Issue

The media selection logic checks the assetCache of AVURLAsset that was used to download the additional media item. After the additional media item is downloaded it is not in the cache, so it keeps picking the same media item over and over again until it finally ends up in the cache after several downloads.


Stall Issue

I downloaded the app container to inspect the contenst of the mvpkg. The StreamInfoBoot.xml shows that the MediaBytesStored and MediaSegments have downloaded. The downloaded fragments are there and look correct (content and file size). The only thing missing is that Completed is set to NO instead of YES.


The last thing it does before stalling is call

URLSession:assetDownloadTask:didLoadTimeRange:totalTimeRangesLoaded:timeRangeExpectedToLoad:. It gets stuck
at 99%. For example:

Loaded: 123.000

Expected: 123.456


There must be a truncation happening to the loaded time ranges causing the system to think that the download never completed even though it has no more bytes to receive.

As a follow-up to this, I burned a DTS incident on it and was told it "works for me!" and that it must be something related to our device configurations.


I failed a Radar to hopefully get a better resolution, because I'm pretty sure this isn't related to my specific suite of test devices: rdar://31925431

I also filed a DTS on this and got the same response. I'm sitting here watching the HLSCatalog v1.3 (iOS 10.3.1) sample app keep trying to download "BipBop Audio 2 - English" endlessly in a loop.

Any update on this?

I'm having the same issues, it's a really big annoyance not being able to download subtitles.

I don;t know if there is a workaround for this.


However, please try with iOS 11 beta 4 (or similar), which should have fixes.

I am able to download additional videos and audios in iOS 11 beta 4.

But at time of playback in offline mode when i am tring to select captions or audio from player API


[self.currentAsset availableMediaCharacteristicsWithMediaSelectionOptions]; hangs and does not come back.

I tried to reproduce same problem with default player "AVPlayerViewController" ut hard luck problem exists there it self.

Does any one else faced the same problem.

.

In my case the download task with the additional media selection NEVER finishes (no matter how often I try). In the HLSCatalog sample I also noticed multiple loops during the download but eventually it finished.

Neither the urlSession(_:task:didCompleteWithError:) nor the

urlSession(_:assetDownloadTask:didLoad:totalTimeRangesLoaded:timeRangeExpectedToLoad:) delegate methods are called for the task with the additional media options.