Shuttor Inc
Shuttor Inc

Reputation: 21

An AVPlayerItem cannot be associated with more than one instance of AVPlayer error playing multiple videos

So I have searched every posting regarding this error and nothing has worked. What happens is that the first time I open the following view controller, everything works. But when I dismiss the controller and try to play the videos a second time, I get this error. Not sure why.

  NSMutableArray *AVPlayerItems;

 AVQueuePlayer *player ;

  NSURL *url = [NSURL fileURLWithPath:filePath];

  AVPlayerItem *firstItem = [AVPlayerItem playerItemWithURL: url3];



       [AVPlaterItems addObject:firstItem];



        player = [AVQueuePlayer queuePlayerWithItems:AVPlayerItems];


            playerController = [AVPlayerViewController new];
            playerController.delegate = self;
            [self.viewPlayer addSubview:playerController.view];
            playerController.view.frame = self.viewPlayer.frame;

            playerController.showsPlaybackControls = NO;


            playerController.player = player;
            [playerController.player play];
        playerController.player.muted = YES;



        [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

Upvotes: 2

Views: 1936

Answers (1)

Jagveer Singh
Jagveer Singh

Reputation: 2328

if(avPlayer==nil)
{

    avPlayer = [AVPlayer playerWithPlayerItem:_avPlayerItem];
}else{
    [avPlayer replaceCurrentItemWithPlayerItem:_avPlayerItem];

}

this will resolve this type of problems

Upvotes: 5

Related Questions