2014-03-01 30 views
0

我試圖播放託管在我的服務器上的視頻。我一直在尋找一段時間,我還沒有解決這個問題。我正在嘗試使用NSURLCredential。MPMoviePlayer播放受保護的網址播放流

這裏是我的代碼:

-(MPMoviePlayerController *)moviePlayerController 
{ 
    NSURL *url = [NSURL URLWithString:@"http://ABCd.com/secret/MOVIE.mov"]; 

    NSURLCredential *credential = [[NSURLCredential alloc] 
           initWithUser: @"username" 
           password: @"password" 
           persistence: NSURLCredentialPersistenceForSession]; 

    NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] 
             initWithHost: [url host] 
             port: 80 
             protocol: [url scheme] 
             realm: nil 
             authenticationMethod: NSURLAuthenticationMethodHTTPBasic]; 
    [[NSURLCredentialStorage sharedCredentialStorage] 
    setDefaultCredential: credential 
    forProtectionSpace: protectionSpace]; 

    _moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
} 

當使用moviePlayerBackDidFinish:(NSNotification *)通知 我收到以下錯誤

去把錯誤:錯誤域= MediaPlayerErrorDomain代碼= -1013「的操作無法完成(MediaPlayerErrorDomain error -1013。)「

任何想法?

+0

歡迎SO使用

realm: nil 

嘗試。您是否確認您已成功連接並獲得訪問權限? – sangony

+0

是的,我確認了一個成功的連接。 – kcajmagic

回答

0

而不是使用

realm: [url host] 
+0

這不適合我。我仍然收到一個錯誤_itemFailedToPlayToEnd:{kind = 1;新= 2;舊= 0;} – kcajmagic

+0

看看這個以前的SO張貼。嘗試在接受的答案中運行測試代碼,並查看是否可以下載簡單的文本文件。如果它適合你,那麼你可以至少消除NSURLCredential連接並下載不工作的問題。 http://stackoverflow.com/questions/7420837/how-to-download-docx-pdf-image-pptx-or-any-file-from-a-internet – sangony

+0

我試過這個我可以下載一個簡單的文件。我不明白該從哪裏出發。 – kcajmagic

相關問題