我一直在尝试从受保护的 url 流式传输电影。我可以下载电影然后播放,但是电影太长了,这很烦人。
这是我的代码:
-(MPMoviePlayerController *)moviePlayerController
{
NSURL *url = [NSURL URLWithString:@"http://ABcDE.com/secret/Movie.mov"];
_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
NSURLCredential *credential = [[NSURLCredential alloc]
initWithUser: @"user"
password: @"password"
persistence: NSURLCredentialPersistencePermanent];
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost: [url host]
port: 80
protocol: [url scheme]
realm: [url host]
authenticationMethod: NSURLAuthenticationMethodDefault];
[[NSURLCredentialStorage sharedCredentialStorage]
setDefaultCredential: credential
forProtectionSpace: protectionSpace];
_moviePlayer.view.frame = CGRectMake(0, 0, 500, 500);
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
_moviePlayer.backgroundView.backgroundColor = [UIColor blackColor];
_moviePlayer.allowsAirPlay = YES;
_moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
return _moviePlayer;
}
我已经尝试将领域链接到 nil 没有工作。我尝试在之后移动 initWitcontnetURL
[[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential: credential forProtectionSpace: protectionSpace];
那也没有用。
从方法 -(void) moviePlayBackDidFinish:(NSNotification*)notification 我得到错误 Error Domain=MediaPlayerDomain Code=-1013 "The operation could not be completed. (MediaPlayerErrorDomain error -1013.)"
查看苹果文档,这是一个 CFNetwork 错误 kCFURLErrorUserAuthenticationRequired = -1013
任何想法如何解决这个问题?