4

I am using AVPlayer to play online movie. It is working fine. Now the problem is, when I pop out from the view before the movie starts playing, the background process keeps running. And when the movie gets loaded, it starts playing in background.

I tried to release the player in viewWillDisappear. But its not working.

- (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 anyone please help? Thanks in advance

Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
Nir
  • 399
  • 3
  • 22

2 Answers2

0

This might help..

    if (self.player.currentItem.playbackLikelyToKeepUp == 1 ) {

    NSLog(@"Ready To Play");
    [self.player play];


    }else{

    NSLog(@" Show HUD Buffering...");

    [self.player pause];

    }
Rahim Jan
  • 126
  • 11
0
- (void)viewWillDisappear:(BOOL)animated
        if (self.player.playing==YES) {
            [self.player stop];
            self.player=nil;
        }
    }
Rakesh Bhatt
  • 4,606
  • 3
  • 25
  • 38
  • 1
    This is valid only when video has started playing. I face this problem when video is not ready to play and thread is working in background. I want to stop this thread. – Nir Jul 05 '11 at 04:50
  • Why would you want to destroy your player in this method? If another view is presented or pushed on top and you go back to this view, you won't have a player anymore. – Stephen Paul Jun 16 '16 at 07:07