IOS Stream Audio from a cookie-enabled server

I am trying to transfer an audio file from a server protected by session-based verification and I noticed that both MPMoviePlayerController and AVPlayerItem / AVPlayer do not use cookies set in NSHTTPCookieStorage. If I make the same URL request using NSURLConnection, I get 200 and can access the audio file. When I track requests through a proxy, it looks like MPMoviePlayerController does not set a cookie in the request header, but NSURLConnection does:

Request with MPMoviePlayerController 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 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 force MPMoviePlayerController or AVPlayerItem to use NSHTTPCookie when requesting a remote resource?

+6
source share
2 answers

AFAIK has no way to force cookies (or any other optional HTTP parameters) when using MPMoviePlayerController in remote streams / files.

Maybe the GET parameter will become a possible workaround for your task?

+1
source

You can intercept the request from MPMoviePlayerController using a class derived from NSURLProtocol and add cookies along this path. Here's the code: fooobar.com/questions/668995 / ...

+3
source

Source: https://habr.com/ru/post/900717/


All Articles