2

I have a kivy-based game that is supposed to play some sound FX. Sound objects are loaded like this:

self.boombox = {'moved': SoundLoader.load('dshoof.wav'),
                'attacked': SoundLoader.load('dspunch.wav')}

And played whenever appropriate like this:

self.parent.boombox['attacked'].play()

It mostly works, but the first time any particular sound is played, it lags for about half a second. I guess that's the time it takes to load WAV from disk to memory. Is there any way to make sure sounds are loaded during initialization, not in a lazy manner it seems to be? This behaviour is observed on Linux-based PC, non Android, if that's of any relevance.

Synedraacus
  • 975
  • 1
  • 8
  • 21

1 Answers1

1

It can be hacked around, as it turned out. All I needed was to set the player to the start of the file explicitly:

self.boombox = {'moved': SoundLoader.load('dshoof.wav'),
                'attacked': SoundLoader.load('dspunch.wav')}
for sound in self.boombox.keys():
    self.boombox[sound].seek(0)

As something like that would've been done anyway, it changes nothing about the sound. However, it forces sound provider to read the file right now instead of waiting until it's called. And, of course, this can be easily done during level loading instead of messing with the gameplay.

Synedraacus
  • 975
  • 1
  • 8
  • 21