I am having an issue setting offset of AVQueuePlayer video. I have tried seek(to function to set offset of the video but it doesn't seem to work. The video always starts from 0 Seconds. Other requirements are playing it with control and looping back which are working fine.
I am kind a stuck at playing the video from any other point other than 0 Seconds.
func getVideoView() -> UIView
{
var videoViewContainer = UIView(frame: CGRect(x: 0, y: 0, width: 375, height: 375))
let videoUrl = URL(string: "https://myvideourl.mp4")
let item = AVPlayerItem(url: videoUrl!)
player = AVQueuePlayer()
playerLooper = AVPlayerLooper(player: player!, templateItem: item)
let time = CMTime(seconds: 17.000000, preferredTimescale: CMTimeScale(1))
player?.seek(to: time, completionHandler: { (handler) in
} )
item.forwardPlaybackEndTime = CMTimeMake(20, 1) // For playing it for 20 Seconds
let layer: AVPlayerLayer = AVPlayerLayer(player: player)
layer.frame = videoViewContainer.bounds
layer.videoGravity = AVLayerVideoGravity.resizeAspectFill
videoViewContainer.layer.addSublayer(layer)
player?.play()
return videoViewContainer
}