使用此错误消息检查网络后应用程序崩溃:AVPlayerItem无法与多个AVPlayer实例关联

时间:2013-05-29 13:21:11

标签: iphone ios mpmovieplayercontroller

我在播放来自互联网的视频时收到了标题中提到的错误。

- (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问题但无法获得单一解决方案

2 个答案:

答案 0 :(得分:0)

您所引用的案例未正确创建您的网址。

您正在尝试播放远程流,因此URL必须是远程流。

使用fileURLWithPath创建本地文件网址。远程URL使用URLWithString创建。

本地文件网址

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

远程网址

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

答案 1 :(得分:0)

好吧这个问题在堆栈溢出上似乎很多,我得到了一个解决方案。大多数面临同一问题的人都有正确的代码但只有问题是我们忘记添加dailymotion,vimeo框架。因为他们提供了自己的框架sdks 您可以从下面的链接下载它们并将它们添加到您的项目中。

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