1

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)
}
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
eonr
  • 29
  • 1
  • 5
  • 30~40 seconds are quite long for me. It makes me feel like something relates to resource or connectivity. Have try different playable asset and networks? You can also get the URL and play from safari to compare the difference. – Breek Jul 31 '17 at 21:33
  • Yes. In safari It takes like 5 second and In vlc, 1-2 second. Does avplayer needs to download all song before seek? – eonr Jul 31 '17 at 21:37
  • I'm not 100% but if the resource supports live streaming, then `AVPlayer` will buffer part of the resource and play from whatever is available. If safari only takes 5 seconds then you should try to create your own `AVPlayer` instance. – Breek Jul 31 '17 at 21:41
  • I think resource does not support live streaming because I'm playing it from my webserver (just like ftp) so It doesn't have anything in backend. – eonr Jul 31 '17 at 21:43
  • @Breek Can problem exist because of function tries to seek it everytime I change the slider? For example when u move slider from 0 to 50 it calls function 50 time. – eonr Jul 31 '17 at 21:54

1 Answers1

0

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.

Emre Önder
  • 2,408
  • 2
  • 23
  • 73