如何在VLCKit中观察更精确的玩家时间



我正试图将MobileVLCKit合并到我的应用程序中,但默认的时间观测器对我来说不够精确,导致进度条在时间之间跳跃。有没有办法获得更精确的时间更新(例如,每1/60秒(?

这是我当前的代码:

let player = VLCMediaPlayer()
func mediaPlayerTimeChanged(_ aNotification: Notification) {
print(player.time)
}
/// 0.0
/// 0.0
/// 0.0
/// 0.1
/// 0.1
/// 0.1
/// 0.2

提前感谢!

由于找不到该选项的文档,我在手动浏览时遇到了以下问题,这似乎是确保mediaPlayerTimeChanged更新更频繁,而且播放媒体的正确更新时间准确的解决方案。

mediaPlayer.timeChangeUpdateInterval = 0.05

您可以使用此解决方案:

func setUpTimer() {
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
self.progressAnimation()
}
}
func progressAnimation() {
UIView.animate(withDuration: 0.003, delay: 0.0, options: [.beginFromCurrentState],
animations: { [weak self] in
self?.progressView.progress = player.position
self?.layoutIfNeeded()
}, completion: nil)
}

调用setUpTimer((函数

try:player.position

例如:

let player = VLCMediaPlayer()
func mediaPlayerTimeChanged(_ aNotification: Notification) {
print(player.position)
}

您还需要获得内容长度,才能将其转换为人类可读的时间,例如:let content_length = player.media.length

最新更新