AVAssetResourceLoaderDelegate and CoreMediaErrorDomain -12881 When Playing HLS Audio

I am developing an app that plays HLS audio. When using AVPlayerItem with AVURLAsset, can AVAssetResourceLoaderDelegate correctly handle HLS segments?

My goal is to use AVAssetResourceLoaderDelegate to add authentication HTTP headers when accessing HLS .m3u8 and .ts files. I can successfully download the files, but playback fails with errors.

Specifically, I am observing the following cases:


A. AVAssetResourceLoaderDelegate is canceled, and CoreMediaErrorDomain -12881 occurs

In NSURLConnectionDataDelegate’s didReceiveResponse method, set contentInformationRequest

In didReceiveData, call dataRequest respondWithData

resourceLoader didCancelLoadingRequest is called

CoreMediaErrorDomain -12881 occurs


B. CoreMediaErrorDomain -12881 occurs

In NSURLConnectionDataDelegate’s didReceiveResponse method, set contentInformationRequest

In connection didReceiveData, buffer all received data until the end

In connectionDidFinishLoading, pass the buffered data to respondWithData

Call loadingRequest finishLoading

CoreMediaErrorDomain -12881 occurs


In both cases, dataRequest.requestsAllDataToEndOfResource is YES.

For this use case, I am not using AVURLAssetHTTPHeaderFieldsKey because I need to apply the most up-to-date authentication data at the moment each file is accessed.

I would appreciate any advice or suggestions you might have. Thank you in advance!

AVAssetResourceLoaderDelegate and CoreMediaErrorDomain -12881 When Playing HLS Audio
 
 
Q