How to play music with playdate.fileplayer?

,

Hi,

I just want to play music with playdate.fileplayer but I can't do it.

With sampleplayer my code works.

local music = playdate.sound.fileplayer.new("path/to/music/file")
music:play()

music is nil???

Thank you.

Your code is ok. You might want to check if you've got any error when creating the player. Like so:

local music, err = playdate.sound.fileplayer.new("path/to/music/file")
print(err)
2 Likes

An error means your path is wrong, or file is wrong.

what's the actual filename you're using? There's some weirdness here because the compiler converts wav and aiff files to our own pdi format, and a sampleplayer and fileplayer have an inconsistency that I still need to fix: if you pass the original file name to sampleplayer.new(), including the wav or aiff extension, it changes it to pdi under the hood. But it looks like fileplayer.new() doesn't, wants that extension trimmed off. :confused:

That's filed, and I'll fix it soon!

Ok, the test write malloc(10421212) failed

huh, that doesn't make any sense. :frowning: The fileplayer streams off disk so it only needs a small amount of memory to buffer the data, 1/2 second by default, or 44kB for 16-bit mono and 88kB for 16-bit stereo. Sampleplayer loads the entire file to memory, so an allocation error there would be less surprising.

Can you post a demo pdx that's showing this error?

Ok so it's a test project for futur big game

and it's works perfectly with sampleplayer

(the file was deleted)

Great, thanks! I don't see any calls to fileplayer.new() happening in there. :thinking: When I put a breakpoint at that error message it's showing that it's getting called from sampleplayer.new(). The Lua stack trace shows that's happening at SplashScene.lua:31.

oh yes sorry, I make a new build

Ok, with fileplayer, the error is Couldn't load file at ./sounds/musics/hardware_and_tear_loop.wav: No error
lol

Ok, it's the .wav the problem...
Sorry

2 Likes