Reputation: 14123
In previous versions there was Done button on AVPlayer and when the following notification was added, it worked :
NotificationCenter.default.addObserver(self, selector: #selector(CourseDetailViewController.moviePlayBackDidFinish(notification:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
Now suddenly, in iOS 11, firstly there is no Done button (it is replaced by cross button), and secondly, on tapping cross button, NSNotification.Name.AVPlayerItemDidPlayToEndTime
is not getting fired.
This is how I am presenting the player with help of AVPlayerViewController
player = AVPlayer(url: url! as URL)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true)
Upvotes: 2
Views: 2162
Reputation: 14580
The documentation states that AVPlayerItemDidPlayToEndTime
is
Posted when the item has played to its end time
which makes sense given the notification's name.
Conversely, tapping the Done (or X) button of your AVPlayerViewController
before the item has finished playing means it won't play to its end time, and the notification therefore won't be posted.
Testing this on iOS 9.3 shows the behaviour is the same as it is on iOS 11.
Something else must have changed in your application, or in iOS 11's interaction with your application, that is causing the change of behaviour you're observing. Without seeing your code anything else would be speculation, but from what you describe, AVPlayerItemDidPlayToEndTime
is behaving as expected.
Upvotes: 3