Is there a way to know whether an AVPlayer
playback has stalled or reached the end?
If you want to check the status of a played video - one of the best solutions is to add an observer to the AVPlayer item . The AVPlayerViewController doesn't notify about the ending of a video. This is why you need to check it by yourself. You should add the NotificationCenter observer to your playVideo() method.
Currently with swift 5 the easiest way to check if the player is playing or paused is to check the . timeControlStatus variable.
AVPlayer does not have a method named stop . You can pause or set rate to 0.0.
Use this method to seek to a specified time for the current player item and to be notified when the seek operation is complete. completion handler will be invoked with the finished parameter set to YES. Use this method to seek to a specified time for the current player item.
You can tell it's playing using:
AVPlayer *player = ... if ((player.rate != 0) && (player.error == nil)) { // player is playing }
Swift 3 extension:
extension AVPlayer { var isPlaying: Bool { return rate != 0 && error == nil } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With