简体   繁体   中英

Faster seek time in AVPlayer when streaming long music

I'm using Jukebox library to stream remote music. Musics that I stream are 60 min long. When I try to seek them, it takes like 30-40 seconds to play. 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.

You can get answer from How to detect the end of slider drag answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM