Hello I am using AVPlayer
for video streaming.This is what I have done to play.
avPlayer = AVPlayer(url: videoURL! as URL)
playerLayer = AVPlayerLayer(player: avPlayer)
playerLayer.videoGravity=AVLayerVideoGravityResizeAspectFill
avPlayer.play()
Now I want to add a UISlider
to move when the video is playing. So I did in this way.
let minimumValue:Float=0.00
sliderBar.minimumValue=minimumValue
playerLayer.frame = self.viewPlayer.bounds
self.viewPlayer.layer.addSublayer(playerLayer)
let duration : CMTime = avPlayer.avPlayer.currentItem!.asset.duration
let seconds : Float64 = CMTimeGetSeconds(duration)
sliderBar.maximumValue=Float(seconds)
But when I print the duration
this is my output
(lldb) po duration
▿ CMTime
- value : 0
- timescale : 0
▿ flags : CMTimeFlags
- rawValue : 17
- epoch : 0
How can I get the duration of this streaming video. Please help me. Thanks