VideoPlayer icon indicating copy to clipboard operation
VideoPlayer copied to clipboard

Not effective index changing

Open HasanBingolbali opened this issue 1 year ago • 9 comments

I realized that when we press the next Video button, previous video still tries to complete the download. This situation puts great burden on network load as well as causing dramatic decrease in video download speed. Is there any quick fixes that you can suggest. Otherwise I can work on creating PR. Thank you in advance

HasanBingolbali avatar Aug 07 '22 16:08 HasanBingolbali

I think you can try to release the AVPlayerItem of the previous video.

wxxsw avatar Aug 08 '22 02:08 wxxsw

static func suspendDownload(url: URL) {
    VideoLoadManager.shared.loaderMap[url]?.downloader.suspend()
}

static func resumeDownload(url: URL) {
    VideoLoadManager.shared.loaderMap[url]?.downloader.resume()
}

This is what I have added to VideoPlayer. Whenever I press the button I manually call suspendDownload and It doesn't keep downloading in the background.

HasanBingolbali avatar Aug 09 '22 19:08 HasanBingolbali

You can set a new collection via VideoPlayer.preload(urls: [URL]) which will automatically cancel the previous preload

wxxsw avatar Aug 15 '22 02:08 wxxsw

Also, GSPlayer has a logic. When the current video playback buffer is insufficient, suspend() will be called automatically, and resume() will be automatically called when the current playing video buffer is sufficient, so the manual call method is unstable.

wxxsw avatar Aug 15 '22 02:08 wxxsw

Related code:

playerBufferingObservation = playerItem.observe(\.loadedTimeRanges) { [unowned self] item, _ in
    ...
     
    if self.bufferProgress >= 0.99 || (self.currentBufferDuration - self.currentDuration) > 3 {
         VideoPreloadManager.shared.start()
    } else {
         VideoPreloadManager.shared.pause()
    }
}

wxxsw avatar Aug 15 '22 02:08 wxxsw

@wxxsw hi, are there any plans to enable us to modify the duration or bufferProgress by myself? Or can I ask how you come to implement that number? I'm struggling with the issue that somehow preloading doesn't work well for me.

mtfum avatar Sep 03 '22 00:09 mtfum

@mtfum Is this what you want?

VideoPlayer.preloadByteCount = 1024 * 1024 // = 1M

wxxsw avatar Sep 03 '22 07:09 wxxsw

@wxxsw Sorry, I didn't get how preloadByteCount works. Am I correct in assuming that lowering the preload size will reduce the time taken to preload?

mtfum avatar Sep 03 '22 18:09 mtfum

@mtfum A preload is a queue that processes incoming urls in turn, each by downloading and caching 0 to preloadByteCount of video content.

wxxsw avatar Sep 05 '22 02:09 wxxsw