簡體   English   中英

應用此錯誤消息檢查網絡后,應用程序崩潰:AVPlayerItem無法與多個AVPlayer實例關聯

[英]App crashes after checking network with this error message : An AVPlayerItem cannot be associated with more than one instance of 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問題,但無法獲得一個解決方案

您所引用的情況未正確創建您的URL。

您正在嘗試播放遠程流,因此URL必須是遠程流。

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

本地文件URL

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

遠端網址

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

好了,這個問題在堆棧溢出上似乎很多,我對此有了解決方案。 面對相同問題的大多數人都有正確的代碼,但唯一的問題是我們忘記添加dailymotion,vimeo框架。 由於它們提供了自己的框架SDK,因此您可以從下面的鏈接下載它們並將其添加到您的項目中。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM