Skip to content

Preloading asset for faster loading#4

Open
mynameisguy wants to merge 4 commits into
doublesymmetry:mainfrom
AlpeAudio:preload-assets
Open

Preloading asset for faster loading#4
mynameisguy wants to merge 4 commits into
doublesymmetry:mainfrom
AlpeAudio:preload-assets

Conversation

@mynameisguy

Copy link
Copy Markdown

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

@dcvz

dcvz commented Nov 6, 2021

Copy link
Copy Markdown
Collaborator

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

@jannemecek

jannemecek commented Nov 10, 2021

Copy link
Copy Markdown

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.

@mynameisguy

Copy link
Copy Markdown
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants