Search code examples
iphoneiosmpmovieplayercontroller

App crashes after checking network with this error message : An AVPlayerItem cannot be associated with more than one instance of AVPlayer


I'm getting this error mentioned in title while playing a video from internet.

- (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......");

}

this is whole code. i have went through most of tutorials,stackoverflow questions but could not get a single solution


Solution

  • well this question seems a lot on stack overflow, i got a solution to this. most of the people facing same issue have right code but only problem is we forget to add dailymotion,vimeo frameworks. since they provide their own framework sdks you can download them from links below and add them to your projects.

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