2013-05-29 16 views
0

我在播放來自Internet的視頻時在標題中提到了此錯誤。使用此錯誤消息檢查網絡後,應用程序崩潰:AVPlayerItem無法與AVPlayer的多個實例關聯

- (void)viewDidLoad 
{ 
    NSString *urlAdress = [NSString stringWithFormat:@"http://www.dailymotion.com/video/x108t8t"]; 
    //NSString *urlAdress = [[NSBundle mainBundle] pathForResource:@"video8" ofType:@"mp4"];in this case video plays. 
    NSURL *videoURL = [NSURL fileURLWithPath:urlAdress]; 
    self.mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(moviePlaybackDidFinish:) 
              name:MPMoviePlayerPlaybackDidFinishNotification 
              object:nil]; 

    self.mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming; 
    //when using file in resources use MPMovieSourceTypeFile,when online then streaming 
    [self presentMoviePlayerViewControllerAnimated:mpvc]; 
    [super viewDidLoad]; 
} 
//and here is moviePlaybackDidFinish method  
- (void)moviePlayBackDidFinish:(NSNotification *)notification 
{ 
MPMoviePlayerController *theMovie = [notification object]; 
[[NSNotificationCenter defaultCenter] removeObserver:self 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:theMovie]; 
[theMovie stop]; 
[theMovie.view removeFromSuperview]; 
NSLog(@" playback finish Called......"); 

} 

這是整個代碼。我已經通過大部分教程,stackoverflow的問題,但不能得到一個單一的解決方案

+0

您是否在同一屏幕上使用MPMoviePlayerViewController的多個實例? –

+0

在您的問題中發佈此方法。這裏很難閱讀。 –

+0

什麼是avplayeritem我dint在我的代碼中使用了這個? – iAhmed

回答

0

好這個問題似乎有很多的堆棧溢出,我得到了解決這個。大多數面臨同樣問題的人都有正確的代碼,但唯一的問題是我們忘記添加dailymotion,vimeo框架。因爲他們提供了自己的框架sdks ,您可以從下面的鏈接下載它們並將它們添加到您的項目中。

http://www.dailymotion.com/doc/api/sdk-objc.html

0

您的URL是不正確創建您引用的情況下。

您正在嘗試播放遠程流,因此該URL需要是遠程流。

本地文件的URL使用fileURLWithPath創建。遠程URL使用URLWithString創建。

本地文件URL

NSURL *videoURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"video8" ofType:@"mp4"]]; 

遠程URL

NSURL *videoURL = [NSURL URLWithString:@"http://www.dailymotion.com/video/x108t8t"]; 
相關問題