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
}
I got the answer. SeekTo doesn't seem to work when use with AVPlayerLooper.
AVPlayerLooper itself has a property time range. Example given below
playerLooper = AVPlayerLooper(player: self.player!,
templateItem: item!,
timeRange: CMTimeRange(start: CMTime(seconds: Double(start), preferredTimescale: 1) , duration: CMTime(seconds: Double(duration), preferredTimescale: 1)))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.