通过MPMoviePlayer流式传输带证书的大电影 [英] Stream large movie with credential through MPMoviePlayer

查看:92
本文介绍了通过MPMoviePlayer流式传输带证书的大电影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试从受保护的网址流式传输电影.我可以下载电影然后再播放,但是电影太长了,所以很烦人.

I've been trying to stream a movie from a url that is protected. I can download the movie then play it, but the movie is too long so this is annoying.

这是我的代码:

-(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.我试过在

I've tried chaining the realm to nil that didn't work. I tried moving the initWitcontnetURL after the

   [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential: credential forProtectionSpace: protectionSpace];           

那也不起作用.

从方法-(void)moviePlayBackDidFinish:(NSNotification *)notification 我收到错误错误Domain = MediaPlayerDomain代码= -1013操作无法完成.(MediaPlayerErrorDomain错误-1013.)"

From the method -(void) moviePlayBackDidFinish:(NSNotification*)notification I get the error Error Domain=MediaPlayerDomain Code=-1013 "The operation couldn't be completed. (MediaPlayerErrorDomain error -1013.)"

查看苹果文档,发现它是CFNetwork错误kCFURLErrorUserAuthenticationRequired = -1013

Looking at apple documentation it is a CFNetwork Error kCFURLErrorUserAuthenticationRequired = -1013

任何想法如何解决这个问题?

Any Ideas how to solve this?

推荐答案

如果您的视频服务器需要基本身份验证,则可以轻松地将其传递到电影播放器​​控制器的URL,例如而不是常规网址,您将以以下格式传递网址:

If your video server expects Basic Authentication, it can be easily passed to the movie player controller's URL, e.g. instead of regular url you will pass url in format:

http(s)://user:password@host/path

然后将播放视频.

这篇关于通过MPMoviePlayer流式传输带证书的大电影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆