我有一个 AVPlayer,每当单击链接时,我都会将其加载到新视图中。
-(void)createAndConfigurePlayerWithURL:(NSURL *)movieURL sourceType:(MPMovieSourceType)sourceType {
self.playerItem = [AVPlayerItem playerItemWithURL:movieURL];
customControlOverlay = [[AFDetailViewController alloc] initWithNibName:@"AFMovieScrubControl" bundle:nil];
backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[customControlOverlay.view setFrame:backgroundWindow.frame];
[backgroundWindow addSubview:customControlOverlay.view];
playerLayer = [AVPlayerLayer playerLayerWithPlayer:[AVPlayer playerWithPlayerItem:playerItem]];
[playerLayer.player play];
playerLayer.frame = customControlOverlay.view.frame;
[customControlOverlay.view.layer addSublayer:playerLayer];
}
上面的代码将 AVPlayer 添加到我的应用程序中并且工作正常。我的 customControlOverlay 笔尖中有一个开关,它应该删除视图并停止播放 AVplayer。
-(IBAction)toggleQuality:(id)sender {
if (qualityToggle.selectedSegmentIndex == 0) {
NSLog(@"HD");
[playerLayer.player pause];
[self.view removeFromSuperview];
} else if (qualityToggle.selectedSegmentIndex == 1) {
NSLog(@"SD");
}
}
视图已正确删除,但播放器仍在后台播放。在测试了一下之后,玩家不会响应 toggleQuality 方法中的任何代码,但是我在那里的字符串作为检查被记录。
对我做错了什么有任何想法吗?