[英]Faster seek time in AVPlayer when streaming long music
I'm using Jukebox library to stream remote music. 我正在使用Jukebox库流式传输远程音乐。 Musics that I stream are 60 min long.
我播放的音乐长达60分钟。 When I try to seek them, it takes like 30-40 seconds to play.
当我尝试寻找它们时,播放大约需要30-40秒。 I changed some codes in the library to make them play immediately for the first time.
我更改了库中的某些代码,以使它们可以立即首次播放。 It worked, but it does not speed up seeking.
它起作用了,但是并没有加快搜索速度。
public func seek(toSecond second: Int, shouldPlay: Bool = false) {
guard let player = player, let item = currentItem else {return}
player.seek(to: CMTimeMake(Int64(second), 1))
item.update()
if shouldPlay {
if #available(iOS 10.0, *) {
player.playImmediately(atRate: 1.0)
} else {
player.play()
}
if state != .playing {
state = .playing
}
}
delegate?.jukeboxPlaybackProgressDidChange(self)
}
From your comment, I found that function calls everytime you slide the slider. 从您的评论中,我发现每次滑动滑块时都会调用该函数。 For example It is called 50 times when you move slider from 0 to 50. So you need to create an eventhandler, which will look wen user stops sliding.
例如,当您将滑块从0移到50时,它被称为50次。因此,您需要创建一个事件处理程序,该事件处理程序将使用户停止滑动。
You can get answer from How to detect the end of slider drag answer. 您可以从“ 如何检测滑块拖动答案的结尾”获得答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.