SwiftAudioEx
SwiftAudioEx copied to clipboard
Preloading asset for faster loading
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
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
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 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.