我使用SOAP web service
. 登录后,我正在查看的许多文件仅对登录用户可用,因此 iOS 必须在其中创建会话NSURL
或其他东西。
尝试使用MPMoviePlayerViewController
它预览视频文件时不起作用,它只是加载 viewController,然后将其关闭。
如果我使用QuickLook
它确实有效,可能是因为我先在本地下载视频,然后再查看它。
但是,我不想这样做,我想使用流式传输视频,MPMoviePlayerViewController
因为我不希望用户必须下载整个视频文件。我看过有关使用的帖子,NSURLCredential
但这似乎对我不起作用。我使用(显然添加了我自己的个人信息):
/**
* 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
在这种情况下不起作用?
为什么所有呼叫都NSURLConnection
使用我的登录凭据(例如下载视频),但MPMoviePlayerViewController
似乎没有使用相同的凭据,并且拒绝播放视频(可能是因为它获取了登录页面)?
有针对这个的解决方法吗?