I think I’m also seeing incorrect lengths with sampleplayer – playdate.sound.sampleplayer:getLength() reports slightly more than double the actual length after using playdate.sound.sampleplayer.new(path) to load from a few different ADPCM wav files (encoded using the ffmpeg command in the docs), although I haven’t investigated it very thoroughly. Could that be the same underlying issue as well, or something different?
I haven’t tried getOffset, but playdate.sound.sampleplayer:setOffset() also requires doubling the value to get it to seek close to the right place.
With SDK 1.12.0, getLength() / getOffset() now return the correct values. Thanks for the fix!
However, there is a new problem that when setOffset is called, the value of getLength() is incorrect.
local gfx = playdate.graphics
gfx.setColor(gfx.kColorBlack)
local _sndPlayer = nil
local _status = "Playing ..."
_sndPlayer = playdate.sound.fileplayer.new("sounds/Test.mp3")
_sndPlayer:play()
_sndPlayer:setFinishCallback(function () _status = "Finished!" end)
function playdate.AButtonDown()
local offset = _sndPlayer:getOffset()
offset += 1
if offset < _sndPlayer:getLength() then
_sndPlayer:setOffset(offset)
end
end
function playdate.update()
gfx.clear()
gfx.drawText(_status , 50, 40)
gfx.drawText("Offset: " .. _sndPlayer:getOffset() , 50, 80)
gfx.drawText("Length: " .. _sndPlayer:getLength() , 50, 120)
end
sampleplayer:setOffset() seems to be completely broken now (as of 1.12.0).
I’m using sampleplayer:setOffset(seconds) followed by sampleplayer:play(1) and it starts at the wrong place in the sample (too early) and doesn’t finish playing before it stops.
In 1.11, I was able to work around the issue by simply halving all the values I got from sampleplayer:getLength and doubling all the values I passed to sampleplayer:setOffset. In 1.12.0, I can’t find any workaround: sampleplayer:getLength now returns the correct value, but sampleplayer:setOffset seeks to the wrong place. I attempted to work around this by adding a multiplier to the value I pass to sampleplayer:setOffset to correct for the wrong start time, which sort of works but crashes the simulator when the sample finishes playing (crash output here). Trying this on device results in a freeze followed by the “Sorry, your Playdate needs to restart” screen without the option to press B for the crash log. The file in question is a stereo ADPCM .wav.