IOS source stream from authenticated URL

I want to transfer an audio file from a source that needs OAuth2 authentication, this is my code, but it does not work.

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; [req setValue:[NSString stringWithFormat:@"Bearer %@", accessToken] forHTTPHeaderField:@"Authorization"]; player = [AVPlayer playerWithURL:req.URL]; [player play]; 

Can you help?

+4
source share
1 answer

The problem is that you add the authentication token as an HTTP header, but then a request using only the URL (and the headers are not included in the URL).

I need to do something like this in my application, but it doesn't seem like it could interfere with the AVPlayer network request (at least not with an open API). So, now I'm looking for either a request for the file itself using NSURLSession (which means there is no streaming - you need to wait for the whole file, or perform complex processing to transfer it to the sound player in pieces), or release the service website to accept my parameter as request parameter, not as an HTTP header.

This question also has some potential problems: Submit headers with AVPlayer request in iOS

+2
source

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


All Articles