P3D file, no sound with pygame (just clicks)

I’ve used packp3d to pack my game. I’m using pygame to play all my sounds. Unfortunately, when the game plays, I hear no sounds (except a tiny clicking sound), each time a sound should play.

When I use multify -tf, I can see the .wav files are in the p3d file. When I load a file, it looks like this:

self.jumpSound = pygame.mixer.Sound(“sound/jump.wav”)

And when I play it I do this:

self.channel = self.jumpSound.play()

This works fine outside of p3d files. What’s going on? Thank you in advance for any assistance.

When you run from a p3d file, the individual asset files like wav files don’t actually exist as individual files on disk. Instead, they are packed into the p3d file, and read from there directly by Panda. This means that Panda tools can operate on these files, but external tools like pygame don’t see them.

So, your two choices are (a) use the Panda sound interface instead of pygame to play these sound files, or (b) unpack the sound files to disk so pygame can find them.

Doing (b) is not difficult if you are building a big application and distributing the audio file in a separately downloadable package (you can use the extract=True keyword with the pdef file() method when you add your wav files to the package), but it’s tricky if all you have is a p3d file. I guess you could explicitly read and write the wav files in Python code, though.

David

drwr, thank you so much. That makes total sense. I’ll use the Panda sound interface.

I must ask, though; is there any sort of “brokerage” method that would allow panda to unzip the subfile and “hand it” to pygame or other 3rd party tools?

You can write the code to unpack it yourself; it’s easy Python code. But there’s nothing built into Panda to do it automatically, unless you are using the full package system. If you are using the package system, Panda will automatically unpack any files named with unpack = True. This doesn’t happen in a p3d file, because p3d files don’t get “installed” the same way that packages do, and there’s no standard place on the hard disk to put the files that get unpacked.

David

Very good, I’ll check out the manual unpacking. Thanks a lot!