VideoPlayer
VideoPlayer copied to clipboard
Not effective index changing
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
I think you can try to release the AVPlayerItem of the previous video.
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.
You can set a new collection via VideoPlayer.preload(urls: [URL])
which will automatically cancel the previous preload
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.
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 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 Is this what you want?
VideoPlayer.preloadByteCount = 1024 * 1024 // = 1M
@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 A preload is a queue that processes incoming urls in turn, each by downloading and caching 0 to preloadByteCount of video content.