UISlider具有缓冲进度 - AVPlayer

问题描述 投票:1回答:1

enter image description here我正在使用AVPlayer从服务器传输音频,我现在要做的是显示一个显示缓冲进度的自定义UISlider。

有人想出这个吗?请给我解决方案。现在玩家加载整个持续时间并在UISlider中显示。

avplayer uislider swift4.2
1个回答
0
投票

你需要使用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你的滑块并在缓冲进行时应用更改。

我可以通过调用drawinside qazxsw poi随时调用qazxsw poi来调用qazxsw poi

bufferValue
© www.soinside.com 2019 - 2024. All rights reserved.