Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check play state of AVPlayer

Is there a way to know whether an AVPlayer playback has stalled or reached the end?

like image 701
Egil Avatar asked Apr 13 '11 21:04

Egil


People also ask

How to detect when AVPlayer video ends playing?

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.

How do I know if AVPlayer is playing or not in swift 5?

Currently with swift 5 the easiest way to check if the player is playing or paused is to check the . timeControlStatus variable.

How do I stop AVPlayer in Objective C?

AVPlayer does not have a method named stop . You can pause or set rate to 0.0.

How do I seek AVPlayer in Swift?

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.


1 Answers

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     } } 
like image 97
maz Avatar answered Oct 16 '22 13:10

maz