Is asynchronous loading possible?

I have a question about how to possibly do async loading of assets. I have a collection of objects, each one has a fileplayer. Each level I refresh the collection of objects, and have to destroy and recreate the fileplayer in each one. This load always results in an unavoidable hiccup. I've separated them out into a timer-based loading routine, so right now I'm getting several short hiccups rather than one long hiccup. I'd love to do this loading even more smoothly. Any advice?

To get some Async loading I think the best would be to write a function in C to load a file in chunks.

However you mention that that you use fileplayer. To my knowedge this type is already loading the file partially, at least it should load the content to fill the buffer. Did you already try to change the buffer size so it would have to load less data?

I also wonder what happends when you call playdate.sound.fileplayer:setBufferSize(seconds) to increase the buffer size. Does it reload the whole buffer or does it load just the bit missing. That would be interesting to try.

For reference for people who might come here in the future, I also put the post Shaun who provided a solution if you have a lot of assets to load.

I've filed a few issues that have come out of this, copying them here for reference

buffer size argument in playdate.sound.fileplayer.new() is ignored, always set to 1/2 second: https://dev.panic.com/Playdate/Playdate/-/issues/89

add fileplayer:load(): https://dev.panic.com/Playdate/Playdate/-/issues/90

when should fileplayers buffer data?: https://dev.panic.com/Playdate/Playdate/-/issues/91

1 Like