Search code examples
iphonecocos2d-iphoneiphone-sdk-3.0mpmovieplayercontroller

How to authenticate in MPMoviePlayer for iPhone


I want to live stream my video files and play it in iPhone.

I am using MPMoviePlayer for playing the video.

I am specifying the url in the below API:

MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:theURL];

But my url asks for user credentials and I am not able to pass the credentials.


Solution

  • I have the same problem. It should be somehow possible by using NSURLCredential, but I wasn't able to figure it out until now.

    Update: I figured it out, look at the documentation of MPMoviePlayerController, there you can see how it works.

    For me it worked like this:

    NSURLCredential *credential = [[[NSURLCredential alloc]
                                       initWithUser: kHTTPSUsername
                                       password: kHTTPSPassword
                                       persistence: NSURLCredentialPersistenceForSession] autorelease];
    
        NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc]
                                                  initWithHost: @"my.secret.host"
                                                  port: 443
                                                  protocol: @"https"
                                                  realm: @"secret.host"
                                                  authenticationMethod: NSURLAuthenticationMethodDefault] autorelease];
    
        [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential: credential forProtectionSpace: protectionSpace];