IOS: playing videos that require authentication works in QuickLook but not in MPMoviePlayerViewController

I went to my server using SOAP web service . After logging in, many of the files I'm viewing are available only to a registered user, so iOS should create a session in NSURL or something like that.

When you try to view the video file using MPMoviePlayerViewController it will not work, it just loads the viewController, and then rejects it.

If I use QuickLook , it works, perhaps because I download the video locally first and then watch it.

But I do not want to do this, I want to stream video using MPMoviePlayerViewController , because I do not want the user to download the entire video file. I saw posts about using NSURLCredential , but this does not seem to work for me. I used (added my personal information):

 /** * Play media session * * @version $Revision: 0.1 */ - (void)playMediaWithURL:(NSString *)mediaURL { // Authenticate NSURLCredential *credential = [NSURLCredential credentialWithUser:@"myusername" password:@"mypassword" persistence:NSURLCredentialPersistenceForSession]; NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] initWithHost:@"mysite.com" port:80 protocol:@"http" realm:nil authenticationMethod:NSURLAuthenticationMethodDefault]; [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credential forProtectionSpace:protectionSpace]; // The movie player NSURL *movieURL = [NSURL URLWithString:[mediaURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; MPMoviePlayerViewController *tempPlayer = [[MPMoviePlayerViewController alloc]initWithContentURL:movieURL]; // Add observer [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; // Properties tempPlayer.moviePlayer.allowsAirPlay = YES; tempPlayer.moviePlayer.shouldAutoplay = YES; tempPlayer.moviePlayer.useApplicationAudioSession = NO; [self presentMoviePlayerViewControllerAnimated:tempPlayer]; [tempPlayer.moviePlayer play]; }//end 

Since this video is only available to registered users, if the video URLs are accessed by a public user, they are provided with an HTML login form. Does NSURLCredential not work in this case?

Why do all calls on NSURLConnection work using my credentials (like downloading a video), but MPMoviePlayerViewController doesn't seem to use the same credentials and refuses to play the video (maybe because it gets the login page)?

Is there a solution for this?

+8
ios objective-c nsurl mpmovieplayercontroller nsurlcredential
source share
2 answers

Check AuthName in your Apache configurator if it uses it in your NSURLProtectionSpace constructor as a value for the realm attribute

EDIT: Sorry, did not view your comment about FORM Authentication. hope this helps someone with BASIC Authentication

0
source share

I recently had a similar issue where I could not pass cookies to MPMoviePlayerController. I found from that solution should use NSURLProtocol. However, it was painful to figure out how to do this, so I thought that for a while I would save people by splitting the encoded solution: https://stackoverflow.com/a/168995/

0
source share

All Articles