Check play state of AVPlayer

Egil picture Egil · Apr 13, 2011 · Viewed 99.1k times · Source

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

Answer

maz picture maz · Feb 15, 2012

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
    }
}