AVPlayer continues to run in the background

I use AVPlayer to play an online movie. It is working fine. Now the problem is that when I exit the view before the movie starts playing, the background process continues to work. And when the movie loads, it starts playing in the background.

I tried to release the player in viewWillDisappear. But it does not work.

- (void)viewWillDisappear:(BOOL)animated { if (self.player.currentItem.status != AVPlayerItemStatusReadyToPlay) { [self.player.currentItem removeObserver:self forKeyPath:kRateKey]; [self.player.currentItem removeObserver:self forKeyPath:kStatusKey]; [self.player.currentItem removeObserver:self forKeyPath:kTimedMetadataKey]; } [self.player pause]; [self.player release]; [self.playerLayerView release]; [super viewWillDisappear:animated]; } 

Can anybody help? thanks in advance

+4
source share
2 answers
 - (void)viewWillDisappear:(BOOL)animated if (self.player.playing==YES) { [self.player stop]; self.player=nil; } } 
0
source

This can help.

  if (self.player.currentItem.playbackLikelyToKeepUp == 1 ) { NSLog(@"Ready To Play"); [self.player play]; }else{ NSLog(@" Show HUD Buffering..."); [self.player pause]; } 
0
source

All Articles