How do I get current playing time and total play time in AVPlayer?

You can access currently played item by using currentItem property:

AVPlayerItem *currentItem = yourAVPlayer.currentItem;

Then you can easily get the requested time values

CMTime duration = currentItem.duration; //total time
CMTime currentTime = currentItem.currentTime; //playing time

Swift 5:

if let currentItem = player.currentItem {
    let duration = CMTimeGetSeconds(currentItem.duration)
    let currentTime = CMTimeGetSeconds(currentItem.currentTime())

    print("Duration: \(duration) s")
    print("Current time: \(currentTime) s")
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)