Nic*_*ard 8 objective-c nsurl mpmovieplayercontroller nsurlcredential ios
我使用a登录我的服务器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
Run Code Online (Sandbox Code Playgroud)
由于此视频仅供登录用户查看,因此如果公共用户访问视频URL,则会向其显示要登录的HTML表单.NSURLCredential在这种情况下不起作用?
为什么所有调用都NSURLConnection使用我登录的凭据(例如下载视频),但MPMoviePlayerViewController似乎没有使用相同的凭据,并且拒绝播放视频(可能是因为它获取了登录页面)?
这个问题有方法解决吗?
最近,我遇到了类似的问题,无法将 cookie 传递给 MPMoviePlayerController。我从堆栈溢出中发现解决方案是使用 NSURLProtocol。尽管如此,弄清楚如何做到这一点仍然很痛苦,所以我想通过分享编码解决方案可以节省人们一些时间:https ://stackoverflow.com/a/23261001/3547099
| 归档时间: |
|
| 查看次数: |
2323 次 |
| 最近记录: |