我正在使用AVPlayer播放在线电影。它工作正常。现在的问题是,当我在电影开始播放之前从视图中弹出时,后台进程会继续运行。当电影加载时,它开始在后台播放。
我试图在viewWillDisappear中释放播放器。但它不起作用。
- (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];
}
有人可以帮忙吗? 提前致谢
答案 0 :(得分:0)
- (void)viewWillDisappear:(BOOL)animated
if (self.player.playing==YES) {
[self.player stop];
self.player=nil;
}
}
答案 1 :(得分:0)
这可能会有所帮助..
if (self.player.currentItem.playbackLikelyToKeepUp == 1 ) {
NSLog(@"Ready To Play");
[self.player play];
}else{
NSLog(@" Show HUD Buffering...");
[self.player pause];
}