Music stops when Playdate is locked and then unlocked

This code:

player = playdate.sound.fileplayer.new()
function setup()
  player:load("Music/FF_CrabWalker_SWv01r02")
  player:play(0);
end

function playdate.update()
  gfx.sprite.update()
end
setup();

will play a piece of music when it starts, but occasionally when I lock the Playdate and then unlock it, the music cuts out. I can test this on other SDK’s if need be, was just wondering if anyone is having the same issue.

Thanks,
-Taylor

My guess is that the file player is running out of buffer while locked. The file player’s default behavior is to stop on underrun (in theory to prevent playback stutter). If this is the case you can fix it by adding player:setStopOnUnderrun(false) to your setup() function between the load and play calls.

If that does result in playback stutter you can also try increasing the buffer size with player:setBufferSize(seconds).

1 Like

i will try this and report back, thanks!

that works! thanks for your help!

2 Likes