MPMoviePlayer播放受保护的网址播放流

时间:2014-03-01 22:59:43

标签: ios video-streaming mpmovieplayercontroller

我正在尝试播放托管在我服务器上的视频。我一直在寻找一段时间,但我还没有解决问题。我正在尝试使用NSURLCredential。

这是我的代码:

-(MPMoviePlayerController *)moviePlayerController
{
     NSURL *url = [NSURL URLWithString:@"http://ABCd.com/secret/MOVIE.mov"];

     NSURLCredential *credential = [[NSURLCredential alloc]
                               initWithUser: @"username"
                               password: @"password"
                               persistence: NSURLCredentialPersistenceForSession];

     NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
                                         initWithHost: [url host]
                                         port: 80
                                         protocol: [url scheme]
                                         realm: nil
                                         authenticationMethod: NSURLAuthenticationMethodHTTPBasic];
     [[NSURLCredentialStorage sharedCredentialStorage]
     setDefaultCredential: credential
     forProtectionSpace: protectionSpace];

     _moviePlayer =  [[MPMoviePlayerController alloc] initWithContentURL:url];
}

使用moviePlayerBackDidFinish :( NSNotification *)通知时 我收到以下错误

完成错误:错误Domain = MediaPlayerErrorDomain Code = -1013“无法完成操作。(MediaPlayerErrorDomain错误-1013。)”

任何想法?

1 个答案:

答案 0 :(得分:0)

而不是使用

realm: nil

尝试使用

realm: [url host]