How to get Duration from AVPlayer (Not AVAudioPlayer)?

slowman21 picture slowman21 · Oct 19, 2010 · Viewed 37.9k times · Source

I would like to make a UISlider(scrubber) for my AVPlayer. But since this is not an AVAudioPlayer, it doesn't have a built in duration. Any suggestion on how to create the Slider for fast forward, rewind and progress of the playback?

I read the doc on AVPlayer, it has a built in seekToTime or seekToTime:toleranceBefore:toleranceAfter:. I don't really understand it. Would this be the answer for my slider? AVPlayer also has addPeriodicTimeObserverForInterval:queue:usingBlock:, is this for getting the duration of my track? Can someone give me an example on how to implement this code? I am not a fan of Apple's documentation. It seems very hard to understand.

Answer

slowman21 picture slowman21 · Oct 22, 2010
self.player.currentItem.asset.duration

Got it!