我一直在嘗試從受保護的URL流式傳輸電影。我可以下載電影然後播放,但電影太長,所以這很煩人。通過MPMoviePlayer流式傳輸大型電影憑證
這裏是我的代碼:
-(MPMoviePlayerController *)moviePlayerController
{
NSURL *url = [NSURL URLWithString:@"http://ABcDE.com/secret/Movie.mov"];
_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
NSURLCredential *credential = [[NSURLCredential alloc]
initWithUser: @"user"
password: @"password"
persistence: NSURLCredentialPersistencePermanent];
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost: [url host]
port: 80
protocol: [url scheme]
realm: [url host]
authenticationMethod: NSURLAuthenticationMethodDefault];
[[NSURLCredentialStorage sharedCredentialStorage]
setDefaultCredential: credential
forProtectionSpace: protectionSpace];
_moviePlayer.view.frame = CGRectMake(0, 0, 500, 500);
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
_moviePlayer.backgroundView.backgroundColor = [UIColor blackColor];
_moviePlayer.allowsAirPlay = YES;
_moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
return _moviePlayer;
}
我已經試過鏈接境界爲零,沒有工作。我試圖移動initWitcontnetURL
[[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential: credential forProtectionSpace: protectionSpace];
也沒有工作。
從方法 - (無效)moviePlayBackDidFinish:(NSNotification *)通知 我得到的錯誤錯誤域= MediaPlayerDomain代碼= -1013 「的操作無法完成(MediaPlayerErrorDomain錯誤-1013)。」
看着蘋果的文檔,這是一個CFNetwork錯誤kCFURLErrorUserAuthenticationRequired = -1013
任何想法如何解決這個問題?
這看起來會有幫助。我對如何訂購所有東西感到困惑。可以評論一個鏈接到你的代碼,所以我可以看到你是如何做到的。 – kcajmagic
我無法鏈接到我的代碼,但我使用我的相關代碼編輯了我的帖子 –
這是否適合您?如果是這樣,你能把它標記爲可接受的解決方案嗎? –