Timeline Progress bar for AVPlayer

后端 未结 8 2220
情深已故
情深已故 2020-12-22 22:31

AVPlayer is fully customizable, unfortunately there are convenient methods in AVPlayer for showing the time line progress bar.

AVPl         


        
8条回答
  •  没有蜡笔的小新
    2020-12-22 22:48

        let progressView = UIProgressView(progressViewStyle: UIProgressViewStyle.Bar)
        self.view.addSubview(progressView)
        progressView.constrainHeight("\(1.0/UIScreen.mainScreen().scale)")
        progressView.alignLeading("", trailing: "", toView: self.view)
        progressView.alignBottomEdgeWithView(self.view, predicate: "")
        player.addPeriodicTimeObserverForInterval(CMTimeMakeWithSeconds(1/30.0, Int32(NSEC_PER_SEC)), queue: nil) { time in
            let duration = CMTimeGetSeconds(playerItem.duration)
            progressView.progress = Float((CMTimeGetSeconds(time) / duration))
        }
    

提交回复
热议问题