Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preloading asset for faster loading #4

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mynameisguy
Copy link

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
Copy link
Collaborator

dcvz commented Nov 6, 2021

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
Copy link

jannemecek commented Nov 10, 2021

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