Reputation: 21
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
Reputation: 2328
if(avPlayer==nil)
{
avPlayer = [AVPlayer playerWithPlayerItem:_avPlayerItem];
}else{
[avPlayer replaceCurrentItemWithPlayerItem:_avPlayerItem];
}
this will resolve this type of problems
Upvotes: 5