TidBits: I wonder why a delegate method is not offered for the Done button touch event. It may be the only thing that's missing...
renssies: I was able to overcome this, but it may only work if AVPlayer is presented full screen I'd think:
1. Define a BOOL in the parent view and set it to YES when AVPlayerItemStatusReadyToPlay:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if (object == self.moviePlayerVC.player && [keyPath isEqualToString:@"status"]) {
// AVPlayer is ready to play
if (self.moviePlayerVC.player.status == AVPlayerItemStatusReadyToPlay) {
AVPlayerMovieIsPlaying = YES;
2. Whenever the parent subviews are being rendered, test if this method was called right after the AVPlayerViewController was either dismissed or switched to Picture in Picture mode (iOS 9):
- (void)viewWillLayoutSubviews {
// if movie stopped playing and AVPlayer was just
// dismissed or switched to PiP, revealing the parent views
if (AVPlayerMovieIsPlaying) { // should be YES if AVPlayer is still up and has played for a while
// now when the "Done" button is tapped in AVPlayerViewController,
// the AVPlayer is not released yet, so you can't check "if (!self.moviePlayerVC)"...
// but the video is now in Pause mode, reporting rate = 0
// and self.view.window checks whether the parent view is shown from under AVPlayer view
if (self.moviePlayerVC.player.rate == 0 && self.view.window) {
[self moviePlayerDidStop]; // do whatever you want after the AVPlayer was dismissed
}
}
}
3. Do whatever you want after the AVPlayer was dismissed:
- (void)moviePlayerDidStop {
AVPlayerMovieIsPlaying = NO;
........