AVAssetResourceLoaderDelegate and TS files error: Error Domain=CoreMediaErrorDomain Code=-12881 "custom url not redirect"

Hello,


I've used AVAssetResourceLoaderDelegate and sucessfully implemented ways to store mp3 and mp4 files.

The problem starts when I try to implement the same thing for HLS. The master playlists (m3u8) are working perfectly fine but when I try the same for .ts files (video segments) I get this error: Error Domain=CoreMediaErrorDomain Code=-12881 "custom url not redirect"

I've tried everything and even using the redirect approach to a filepath URL fails.

The only possible solution is to have an internal HTTP server but that doesn't make sense to me. If I'm implementing AVAssetResourceLoaderDelegate then I should be apple to feed AVFoundation the data needed to play a video, right?

Thanks in advance.

Help for this would be much appreciated.

Replies

I stumbled onto this question while looking to customize the HTTP request for media segments. Although I am able to redirect the media segment request using AVAssetResourceLoadingRequest.setRedirect, an authorization header (Authorization: ***) added to the redirect request is not sent in the request. In fact, none of the custom header are used by the player. This is very limiting to not able to use basic HTTP protocol for the media request. I would like to avoid adding authorization token to the query param for data security reasons.
How to play a m3u8 media on a self-signed certificate server? Is there any way to trust all server certificate in AVFoundation framework?
I have the same situation as the original author; I'm able to use the AVAssetResourceLoaderDelegate with a custom scheme to redirect my playlists (master, media, audio, iframe), but when it comes to the segments, I'm unable to redirect them.

My usage scenario is that I need to attach OAuth tokens, and can't put them in the URL itself, I have to put them in the header. It's not clear to me why we can't redirect for the segment fetches, as can't byte ranges be respected in the requests?

I've looked at the DataTasks mentioned, but they seem to for a different solution. We already have custom downloader (data task fetcher), URLCache, and Session and just need to redirect the mp4 fragment segments themselves.

Currently we're forced to use a reverse proxy to handle the entire flow. I was hoping to flip it back to using the AVAssetResourceLoaderDelegate and was happy to see it's easy for the m3u playlists, but segments are a step backwards.

How does the DataTask solution accomplish us just putting new auth headers on requests? How are we supposed to add auth headers to our AVURLAsset playlists and segments?

Did you success on partially downloading task with AVAssetDownloadTask? I am doing a preloading task to preload the first segments of playable data of the next content when playing the current content, would like to know if it is feasible by using this API for any media file preloading, other than playlists.