Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController and Auth-Based HLS Backend Server

I am currently serving videos in my iOS application with MPMoviePlayerController. The files are streamed from our backend server that requires authentication. It is key-based authenticated set in the Authorization HTTP Header.

It used to work perfectly with single video files. Now we’re trying to implement HLS adaptive streaming and we have faced a wall. I am currently using a custom NSURLProtocol subclass to catch requests made to our backend server and inject the proper Authorization header. For HLS it simply doesn’t work.

When we looked at the server logs, we clearly saw that the first request to the m3u8 file worked fine. Then all subsequent calls made (other m3u8 files and ts also) are 403 forbidden. It seems that MPMoviePlayerController doesn’t use NSURLProtocol for the other files. (side note: It does work on the simulator thought, but not on a physical device which let me think that both are not implemented in the same way).

MPMoviePlayerController instantiation

self.videoController = [[MPMoviePlayerController alloc] initWithContentURL:video.videoURL];

The URL Protocol interception

+ (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
    NSMutableURLRequest *newRequest = request.mutableCopy;
    [newRequest setValue:@"HIDDEN" forHTTPHeaderField:@"Authorization"];
    return newRequest;
}

Any Ideas, suggestions, work arounds?

like image 302
Marc-Alexandre Bérubé Avatar asked Nov 08 '22 18:11

Marc-Alexandre Bérubé


1 Answers

After verification with Apple Developer Technical Support, I figured what I wanted to achieve is impossible (and unsupported).

Here's the quote from the reply :

The problem you're seeing with NSURLProtocol and so on is that the movie playback subsystem does not run its HTTP requests within your process. Rather, these requests are run from within a separate system process, mediaserverd. Thus, all your efforts to affect the behaviour of that playback are futile.

like image 124
Marc-Alexandre Bérubé Avatar answered Nov 15 '22 06:11

Marc-Alexandre Bérubé