-
Notifications
You must be signed in to change notification settings - Fork 144
Description
Hi ! Thank you for this example of PreloadManager.
I have noticed a small issue, I don't know if this is intentional or not so please do tell.
When scrolling forward the app preloads the 2 next item under a certain threshold, but when scrolling back, it doesn't add the 2 previous items.
where x is the user current video index
x 0 -> NOT PRELOADED
1 -> PRELOADED
2 -> PRELOADED
3 -> PRELOADED
4 -> PRELOADED
...
0 -> NOT PRELOADED
1 -> NOT PRELOADED and removed from dequeue
2 -> NOT PRELOADED and removed from dequeue
x 3 -> PRELOADED
4 -> PRELOADED
5 -> PRELOADED
6 -> PRELOADED
0 -> NOT PRELOADED
1 -> NOT PRELOADED and removed from dequeue
x 2 -> NOT PRELOADED and removed from dequeue
3 -> PRELOADED
4 -> PRELOADED
5 -> PRELOADED
6 -> PRELOADED
So when going back to index 2, it's not preloading index 1 or 0. Keeping the 2 previous items is quite easy with the snippet below, but there is still the process of getting the starting video back to preload
private fun preloadNextItems() {
var lastPreloadedIndex = 0
if (!preloadWindow.isEmpty()) {
lastPreloadedIndex = preloadWindow.last().second
}
if (lastPreloadedIndex - currentPlayingIndex <= itemsRemainingToStartNextPreloading) {
for (i in 1 until (preloadWindowMaxSize - itemsRemainingToStartNextPreloading)) {
addMediaItem(index = lastPreloadedIndex + i)
if(preloadWindow.size > preloadWindowMaxSize + 2) {
removeMediaItem()
}
}
}
// With invalidate, preload manager will internally sort the priorities of all the media items added to it, and trigger the preload from the most important one.
defaultPreloadManager.invalidate()
}