Timeline Progress bar for AVPlayer

后端 未结 8 2198
情深已故
情深已故 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:46

    I know it's an old question, but someone may find it useful. It's only Swift version:

     //set the timer, which will update your progress bar. You can use whatever time interval you want
    
     private func setupProgressTimer() {
        timer = Timer.scheduledTimer(withTimeInterval: 0.02, repeats: true, block: { [weak self] (completion) in
            guard let self = self else { return }
            self.updateProgress()
        })
    }
    
    //update progression of video, based on it's own data
    
    private func updateProgress() {
        guard let duration = player?.currentItem?.duration.seconds,
            let currentMoment = player?.currentItem?.currentTime().seconds else { return }
    
        progressBar.progress = Float(currentMoment / duration)
    }
    

提交回复
热议问题