每当点击链接时,我会将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添加到我的应用程序中,并且运行良好。我在自定义控制覆盖nib中有一个切换开关,应该移除视图并停止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方法中的任何代码作出响应,但我在那里检查的字符串会被记录。
你有什么想法我做错了什么吗?