8

我使用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似乎没有使用相同的凭据,并且拒绝播放视频(可能是因为它获取了登录页面)?

有针对这个的解决方法吗?

4

1 回答 1

0

最近,我遇到了类似的问题,无法将 cookie 传递给 MPMoviePlayerController。我从堆栈溢出中发现解决方案是使用 NSURLProtocol。尽管如此,弄清楚如何去做还是很痛苦,所以我想我可以通过分享编码解决方案来节省人们一些时间:https ://stackoverflow.com/a/23261001/3547099

于 2014-04-24T06:11:22.813 回答