Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Stream Audio From Server With Cookie-based Auth

I'm trying to stream an audio file from a server protected by session-based authentication, and I've noticed that both MPMoviePlayerController and AVPlayerItem / AVPlayer do not appear to be using the cookies set in NSHTTPCookieStorage. If I make the same URL request using an NSURLConnection, I get a 200 and am able to access the audio file. When I monitor the requests through a proxy, it appears that MPMoviePlayerController does not set the cookie in the request header, while NSURLConnection does:

Request made with MPMoviePlayerController's initWithContentURL:

GET /path/on/server/test1.m4a HTTP/1.1
Host: server.example.net
User-Agent: AppleCoreMedia/1.0.0.9A334 (iPhone Simulator; U; CPU OS 5_0 like Mac OS X; en_us)
Accept: */*
Range: bytes=0-1
Accept-Encoding: identity
X-Playback-Session-Id: E8F093F4-C906-46A8-94FE-30BBCFDAB3F6
Connection: keep-alive

Request made with NSURLConnection:

GET /path/on/server/test1.m4a HTTP/1.1
Host: server.example.net
User-Agent: otest (unknown version) CFNetwork/548.0.3 Darwin/11.1.0
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Cookie: somekey=abc123def456
Connection: keep-alive

Does anyone know how to get MPMoviePlayerController or AVPlayerItem to use an NSHTTPCookie when requesting a remote resource?

like image 860
Andy R Avatar asked Nov 03 '11 17:11

Andy R


2 Answers

You can intercept the request from MPMoviePlayerController using a class derived from NSURLProtocol and inject cookies along the way. Here's the code: https://stackoverflow.com/a/23261001/3547099

like image 159
jacklehamster Avatar answered Nov 14 '22 01:11

jacklehamster


There is AFAIK no way to enforce cookies (or any other additional HTTP-parameters) when using MPMoviePlayerController on remote streams / files.

Maybe a GET-Parameter would be a possible workaround for your task?

like image 25
Till Avatar answered Nov 14 '22 01:11

Till