SwiftAudioEx icon indicating copy to clipboard operation
SwiftAudioEx copied to clipboard

Preloading asset for faster loading

Open mynameisguy opened this issue 3 years ago • 3 comments

Adding SwiftAudioEx the ability to preload assets helps create a better experience when playing few tracks in a row. The implementation is based on https://github.com/nishanBende/SwiftAudio/tree/preloading-asset implementation

mynameisguy avatar Oct 10 '21 08:10 mynameisguy

Thanks for the PR @mynameisguy! I'll take a closer look at this in the upcoming week. It would also be great to add some tests around this functionality

dcvz avatar Nov 06 '21 13:11 dcvz

The preload function doesn't take AssetOptionsProviding into account the same way regular load works. This is necessary in case we need to play links that require authentication.

Preload should be updated to use this info as well. In my case updating the preload function to be like this was sufficient

    func preload(item: AudioItem) {
        let urlString = item.getSourceUrl()
        let url =  URL(string: urlString)

        let options = (item as? AssetOptionsProviding)?.getAssetOptions()
        let asset = AVURLAsset(url:url!, options: options)
        ...

Edit: I would also make the preloadNext function public since it seems to be designed to be used externally. Also, it would probably make sense to have a preloadPrevious in case the user starts playing from the middle of an album for example.

jannemecek avatar Nov 10 '21 00:11 jannemecek

@jannemecek thanks for the comments. Change to public function & passed options as you suggested.

@dcvz tbh I'm not really programming in swift. I believe someone more experienced in Swift writing tests will be a better way to proceed.

mynameisguy avatar Nov 17 '21 09:11 mynameisguy