6

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?

Andy R
  • 145
  • 1
  • 9

2 Answers2

3

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

Community
  • 1
  • 1
jacklehamster
  • 311
  • 3
  • 6
1

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?

Till
  • 27,559
  • 13
  • 88
  • 122
  • 2
    This is basically what I found too. I ended up forking Matt Gallagher's AudioStreamer and modifying it to support custom HTTP headers: https://github.com/arifken/AudioStreamer – Andy R Feb 13 '12 at 18:53