I have an AVPlayer that I upload to a new view whenever a link is clicked.
-(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]; }
The above code adds AVPlayer to my application and works great. I have a switch in my customControlOverlay nib that should remove the view and stop playing AVplayer.
-(IBAction)toggleQuality:(id)sender { if (qualityToggle.selectedSegmentIndex == 0) { NSLog(@"HD"); [playerLayer.player pause]; [self.view removeFromSuperview]; } else if (qualityToggle.selectedSegmentIndex == 1) { NSLog(@"SD"); } }
The view has been deleted correctly, but the player is still playing in the background. After testing the bit, the player will not respond to any code in the toggleQuality method, but the lines that I have when the checks are logged.
Any thoughts on what I'm doing wrong?
source share