Fileplayer:play(0) and fileplayer:isPlaying() works reliably on Simulator, not on Hardware

Windows, SDK 1.13.3, plus actual hardware that's 'System: up to date'.

I know there are all sorts of sound/music related issues posted, but not quite like this one (I think).

The main game ('oh, you're in a dungeon!') has a theme music, but there is other music associated with other areas/actions (ex: 'oh, you're fighting something, play dramatic music instead of main theme').

It turns out, on actual hardware, all sorts of things can interrupt fileplayer:play(0) from actually playing. Hitting the datastore seems to be the top culprit (like 'loading and transitioning to another level') also something that doesn't happen on Simulator.

Ok, so... that's something that can be worked around, using fileplayer:isPlaying(). Loaded the new dungeon level transitioning from another dungeon level, but the dungeon music stopped running? No problemo, check for that via fileplayer:isPlaying() and play it if it isn't. But - on actual hardware, fileplayer:isPlaying() doesn't work - it will often give you a 'false positive' and return 'true' when it actually isn't.

So, on actual hardware, I've currently got a choice between just forcing a 'music_main:play(0)' on every transition into a level (which can be jarring, because if it was already playing it will just start again at the beginning from somewhere mid-music) and... well, that's the only choice, really, as there's no way (on hardware) to make a call to fileplayer:isPlaying() that can be relied upon. Works fine on Simulator, but not hardware.

I've tried things like 'setLoopRange' (no joy) and re-encoding the music to plain-vanilla WAV (also no joy).

We're still in Alpha (may get to Beta in a month or two, i18n still to do and that gets its own regression pass), so this isn't an immediate concern. But I'd prefer to not launch with the music in this state.

Maybe you can avoid the problem by preventing buffer underrruns. Try using a buffer of two seconds to see if that helps.
And playdate.sound.fileplayer:setStopOnUnderrun(false)

3 Likes

The last time I tried setting the buffer fileplayer stopped working altogether, but I'll give that another try. :slight_smile:

:
music_main:setBufferSize(2)
music_main:setStopOnUnderrun(false)
:

Yes! That seems to have worked around the issue where fileplayer:play(0) was getting turned off when something else was hitting the datastore at the same time.

The trick was to set the buffer size to something large enough to ensure no under-run while playing and something else was hitting the datastore, but small enough so as to not fail... by that, I mean when I last tried setting the size I'd tried setting it to the entire length of the file in seconds (which seemed like the right thing to do at the time, but in retrospect now seems pretty dumb :slight_smile: ) and so fileplayer wouldn't work at all.

There seems (to me, at least) that there's still a bug in fileplayer:isPlaying() - if the fileplayer did in fact under-run its buffer and stop, then 'isPlaying()' shouldn't be returning 'true'.

But - things seem much better behaved, at least so far!

1 Like