iOS:播放需要validation的video在QuickLook中播放,但不在MPMoviePlayerViewController中播放

我使用SOAP web servicelogin到我的服务器。 login后,我正在查看的许多文件只能用于login用户,所以iOS必须在NSURL创build会话或其他内容。

当试图使用MPMoviePlayerViewController预览video文件时,它不会工作,它只是加载viewController,然后解散它。

如果我使用QuickLook它可以工作,可能是因为我先在本地下载video,然后查看它。

但是,我不想这样做,我想使用MPMoviePlayerViewControllerstreamvideo,因为我不希望用户不得不下载整个video文件。 我已经看到有关使用NSURLCredentialpost,但这似乎不适用于我。 我使用(显然添加了我自己的个人信息):

 /** * 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 

由于此video只能由login用户查看,如果videoURL由公共用户访问,则会显示一个HTML表单以供login。 NSURLCredential在这种情况下不起作用吗?

为什么所有调用NSURLConnection工作,使用我login的凭据(如下载video),但MPMoviePlayerViewController似乎并没有使用这些相同的凭据,并拒绝播放video(可能是因为它得到的login页面)?

有针对这个的解决方法吗?

检查你的Apacheconfiguration中的AuthName ,如果它被设置,在你的NSURLProtectionSpace构造函数中使用它作为realm属性的值

编辑:对不起,没有看到您对FORMauthentication的评论。 希望它能帮助有BASICauthentication的人

最近,我有一个类似的问题,无法将cookie传递给MPMoviePlayerController。 我发现堆栈溢出解决scheme是使用NSURLProtocol。 尽pipe如此,我还是很痛苦的,所以我想通过分享代码解决scheme来节省一些时间: https : //stackoverflow.com/a/23261001/3547099