eroscai / SZAVPlayer

SZAVPlayer is a lightweight audio/video player library, based on AVPlayer and AVAssetResourceLoaderDelegate, pure-Swift. Support cache and video image output.
MIT License
228 stars 32 forks source link

Clarification on eager loading. #11

Open 8secz-johndpope opened 3 years ago

8secz-johndpope commented 3 years ago

EAGER LOADING This repo by @ChrishonWyllie https://github.com/ChrishonWyllie/Celestial

Provides an easy way to kick off a download like this Celestial.shared.startDownload(for: url)

By hooking into uikit method -

extension VideoVC: UICollectionViewDataSourcePrefetching {
    func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) {
            //  urls for next video in collectionview
             Celestial.shared.startDownload(for: url) // go and get the video
    }
}

We can eagerly kick off the download in background - no ui /and then user scrolls to video / or navigates to the page where it's needed - it will then automatically intercept the request in background and make plays in player.

Can this repo do this?

eroscai commented 3 years ago

If i understand correctly, you want preload some videos, but don't want them to start playing automatically, wait until the cell slides to the position.

I took a look at the startDownload function of Celestial repo. This function is just to make regular file download request, and then there may be some managers to manage the download status to these files. This kind of operation may seem to make the video play smoothly when the cell scrolls, but it may cause some side effects. E.g:

But if you just want to achieve this function, you can use a dedicated library to pre-downloading, like this one? Then set the downloaded file path to the player when needed, or set remote url if it is not downloaded.

The best solution is to provide a preload function in the library, preload part of the content at the beginning, and then use it in conjunction with the existing cache function. This will take a lot of time to implement, maybe I will do this later if i have enough time.

8secz-johndpope commented 3 years ago

There's some magic in that - if the player requests the video being downloaded - it will merge the existing request into avplayer loading....

Screen Shot 2021-08-16 at 2 10 41 am