播放需要身份验证的视频在QuickLook中有效

播放需要身份验证的视频在QuickLook中有效

本文介绍了iOS:播放需要身份验证的视频在QuickLook中有效,但在MPMoviePlayerViewController中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我使用 SOAP Web服务登录我的服务器。登录后,我正在查看的许多文件仅供登录用户使用,因此iOS必须在 NSURL 中创建会话。

I login to my server using a SOAP web service. Once logged in, many of the files that I am viewing are only available to the logged in user, so iOS must create a session in NSURL or something.

当尝试使用 MPMoviePlayerViewController 预览视频文件时,它将无法正常工作,它只会加载viewController,然后将其解除。

When trying to preview a video file using MPMoviePlayerViewController it will not work, it just loads up the viewController, then dismisses it.

如果我使用 QuickLook 它确实有效,可能是因为我首先在本地下载视频,然后查看它。

If I use QuickLook it does work, probably because I download the video locally first, then view it.

但是,我不想这样做,我想使用 MPMoviePlayerViewController 来流式传输视频,因为我不希望用户必须下载整个视频文件。我见过关于使用 NSURLCredential 的帖子,但这对我来说似乎不起作用。我使用过(显然添加了我自己的个人信息):

But, I don't want to do it this way, I want to stream the video using MPMoviePlayerViewController because I don't want the user to have to download an entire video file. I have seen posts about using NSURLCredential but that doesn't seem to work for me. I used (added my own personal info obviously):

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

由于此视频只能通过记录来查看在用户中,如果公共用户访问视频URL,则会向他们显示要登录的HTML表单。 NSURLCredential 在这种情况下不起作用吗?

Since this video is only viewable by a logged in user, if the video URL is accessed by a public user, they are presented with an HTML form to login. Does NSURLCredential not work in this case?

为什么所有调用 NSURLConnection 工作,使用我登录的凭据(例如下载视频),但 MPMoviePlayerViewController 似乎没有使用相同的凭据,并拒绝播放视频(可能是因为它获得了登录页面)?

Why do all calls to NSURLConnection work, using my logged in credentials (such as downloading the video), but MPMoviePlayerViewController doesn't seem to use those same credentials, and refuses to play the video (probably because it gets the login page)?

有解决方案吗?

推荐答案

最近,我遇到了类似的问题,无法将cookie传递给MPMoviePlayerController。我从堆栈溢出中发现解决方案是使用NSURLProtocol。尽管如此,弄清楚如何去做也很痛苦,所以我想我会通过共享编码解决方案节省一些时间:

Recently, I had a similar problem not being able to pass cookies to MPMoviePlayerController. I found from stack overflow that the solution is to use NSURLProtocol. Still, it was painful figuring out how to do it, so I thought I'd save people some time by sharing the coded solution: https://stackoverflow.com/a/23261001/3547099

这篇关于iOS:播放需要身份验证的视频在QuickLook中有效,但在MPMoviePlayerViewController中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:12