SDK 1.12 on Mac.
I'm trying to have a fileplayer call a function when playback completes, using setFinishCallback(). Since it's being handled by an object, i am trying to pass the object as the second arg then use that in the callback function. (I've tried this both with and without that second arg)
When playback completes, the simulator completely crashes out.
Maybe I'm holding it wrong, and that's fine, but the docs make it seem like this should work...
Here is the complete source code to reproduce the issue:
import "CoreLibs/utilities/where"
import 'CoreLibs/animator'
import "CoreLibs/object"
import "CoreLibs/graphics"
import "CoreLibs/sprites"
import "CoreLibs/timer"
import "CoreLibs/animator"
import "CoreLibs/ui"
---------------------
local gfx <const> = playdate.graphics
---------------------------------------------
class( 'PlayerTest' ).extends( 'Object' )
function PlayerTest:init()
PlayerTest.super.init( self )
-- get a new fileplayer with a 1 second buffer
self.thePlayer = playdate.sound.fileplayer.new( 1 )
self:Go()
end
function PlayerTest:describe()
local pcnt = 0
if self.thePlayer:isPlaying() then
local offs = self.thePlayer:getOffset()
local len = self.thePlayer:getLength()
return string.format( "%01.1f / %01.1f", offs, len )
end
return "-"
end
function finishedPlaying( ply, obj )
-- this crashes?
print( '---1---' )
printTable( ply )
print( '---2---' )
printTable( obj )
--obj:Go()
end
function PlayerTest:Go()
-- load in this short mp3 and play it
self.thePlayer:load( 'conet_numbers.mp3' )
self.thePlayer:play()
-- set the finish callback with a second parameter
self.thePlayer:setFinishCallback( finishedPlaying, self )
end
local pt = PlayerTest()
function playdate.update()
gfx.clear(gfx.kColorWhite)
playdate.drawFPS( 20, 20 )
gfx.drawText( pt:describe(), 20, 80 )
end
This 415k zip contains the code, the mp3 that I was testing with and the crash dump: https://umlautllama.com/tmp/playdate.TestFileplayer.zip
(note: the mp3 used in the zip is from the Conet Project, snagged from archive.org... it's a 21 second long mp3 file.)