4
votes

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

2
did you retain player object anywhere, because after releasing it will still be there, so you need to check retain count of player objectiMOBDEV
Thanks for the suggestion. Will check that.Nir

2 Answers

0
votes
- (void)viewWillDisappear:(BOOL)animated
        if (self.player.playing==YES) {
            [self.player stop];
            self.player=nil;
        }
    }
0
votes

This might help..

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

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


    }else{

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

    [self.player pause];

    }