我有一个受Windows身份验证保护的.mp4视频(网址)。我想使用MPMoviePlayerController播放。
我已经实现了一些代码,我确信我已经接近了!
所以,我正在尝试使用NSURLConnection“解锁”mp4网址。它工作,但当我尝试使用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-这被称为正确。从这里开始,这很棒,因为我知道网址是解锁的。那么......如何使用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]];
}