Skip to content

Instantly share code, notes, and snippets.

@melvinbeemer
Last active January 7, 2023 23:30
Show Gist options
  • Save melvinbeemer/ed52b8efa7b3ffeb901a to your computer and use it in GitHub Desktop.
Save melvinbeemer/ed52b8efa7b3ffeb901a to your computer and use it in GitHub Desktop.
Check if AVPlayer is currently playing an item
import Foundation
import AVFoundation
extension AVPlayer {
var isPlaying: Bool {
if (self.rate != 0 && self.error == nil) {
return true
} else {
return false
}
}
}
@Ge0rges
Copy link

Ge0rges commented Jun 15, 2017

You can one line it by doing return (self.player.rate != 0 && self.player.error == nil)

@nodahikaru
Copy link

player.timeControlStatus == AVPlayer.TimeControlStatus.playing
Also this works for it

@vikileak
Copy link

vikileak commented Jan 7, 2023

Thanks @nodahikaru that works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment