8

我使用SOAP web service登錄到我的服務器。登錄後,我正在查看的許多文件只能用於登錄用戶,因此iOS必須在NSURL或其他內容中創建會話。iOS:播放需要身份驗證的視頻在QuickLook中播放,但不在MPMoviePlayerViewController中播放

當試圖使用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 

因爲這個視頻只是一個登錄的用戶可見的,如果視頻的網址是由公共用戶訪問,他們都帶有HTML表單登錄。 NSURLCredential在這種情況下不起作用嗎?

爲什麼所有撥打NSURLConnection的電話都使用我登錄的憑據(例如下載視頻),但MPMoviePlayerViewController似乎沒有使用這些相同的憑據,並拒絕播放視頻(可能是因爲它獲得登錄頁)?

有沒有解決方案?

+0

+1好的問題 - 對答案好奇。一般來說,MPMoviePlayerController(就像前者所依賴的AVPlayer一樣)似乎沒有充分利用這種共享的高級網絡功能。 – Till 2012-03-21 09:45:59

+0

我正在使用我的iOS開發支持門票之一,並將此問題發送給Apple。將看到他們說什麼.. – 2012-03-21 16:14:13

+0

這一個的任何消息? – Till 2012-07-27 20:54:31

回答

0

檢查AuthName在你的Apache配置,如果它被設置使用它在你的NSURLProtectionSpace構造爲值realm屬性

編輯:對不起,沒看到你的評論關於FORM認證。希望它可以幫助BASIC身份驗證

0

最近,我有一個類似的問題,無法將cookie傳遞給MPMoviePlayerController。我發現堆棧溢出解決方案是使用NSURLProtocol。不過,這是痛苦搞清楚如何做到這一點,所以我想我會通過共享編碼的解決方案一段時間救人:https://stackoverflow.com/a/23261001/3547099