你需要使用preferredforwardbufferduration
此属性定义首选的正向缓冲持续时间(以秒为单位如果设置为0,播放器将为大多数用例选择适当的缓冲级别。将此属性设置为较低值将增加播放停止和重新缓冲的可能性,而将其设置为较高值将增加对系统资源的需求。
另请查看此处有关如何使用的详细示例:Is it possible to pause and resume buffering of AVPlayer?
在你的播放器内你需要使用以下功能观察时间范围
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?)
像这样:
let timeRanges = change![NSKeyValueChangeKey.newKey] as? NSArray
if timeRanges != nil && timeRanges!.count != 0 {
DispatchQueue.main.async {
let cmTimeRange = (timeRanges![0] as AnyObject).timeRangeValue as CMTimeRange
self.playerView.timeSlider.bufferValue = Float(CMTimeGetSeconds(cmTimeRange.start) + CMTimeGetSeconds(cmTimeRange.duration))
}
}
我有一个自定义滑块,其变量我定义为bufferValue
你可以覆盖func draw(_ rect: CGRect)
inside你的滑块并在缓冲进行时应用更改。
我可以通过调用draw
inside qazxsw poi随时调用qazxsw poi来调用qazxsw poi
bufferValue