繁体   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