我有一个受 Windows 身份验证保护的 .mp4 视频(url)。我想使用 MPMoviePlayerController 播放。
我已经实现了一些代码,我确定我已经接近了!
所以,我正在尝试使用 NSURLConnection 来“解锁”mp4 url。它可以工作,但是当我尝试使用 initWithContentURL 访问相同的 url 时,它不起作用。(它不能“看到”我之前输入的信息。
所以,问题是;如何永久锁定文件夹/url,或者如何为 MPMoviePlayerController 提供 NSURLConnection 而不是 NSURL。
1-所以,这是我采取的步骤:
- (void)viewDidLoad{
[super viewDidLoad];
//[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"]]];
[self tryConnection];
}
2--> 我正在尝试访问受保护的 URL(这是有效的)
- (void) tryConnection{
NSURLRequest* request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.abcd.com/_develop/video/01.mp4"]];
NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
//[request release];
//[connection release];
}
3-这是正确调用的
- (BOOL)connection:(NSURLConnection*)conn canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace {
if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodNTLM])
return YES;
// Explicitly reject ServerTrust. This is occasionally sent by IIS.
if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])
return NO;
return NO;
}
4-这是正确调用的
- (void)connection:(NSURLConnection*)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge{
NSLog(@"didReceiveAuthenticationChallenge");
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodNTLM])
[[challenge sender] useCredential:[NSURLCredential
credentialWithUser:@"1234"
password:@"5678"
persistence:NSURLCredentialPersistenceNone] forAuthenticationChallenge:challenge];
}
4-这是正确调用的。从这里开始,太好了,因为我知道该 url 是 Unlock。那么...如何使用 MPMoviePlayer 播放它?
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;{
NSLog(@"received response via nsurlconnection");
[self moviePlayerGO];
}
4-保持黑色... :(
-(void)moviePlayerGO{
NSURL *movieURL = [NSURL URLWithString:@"http://www.abcd.com/_develop/video/01.mp4"];
//NSURL *movieURL = [NSURL URLWithString:@"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayer.shouldAutoplay = YES;
[[moviePlayer view] setFrame: CGRectMake(0.0, 0.0, 350.0, 250.0)]; // 2X the native resolution
[self.view addSubview: [moviePlayer view]];
}