Sound Support¶
These classes allow you to play sounds in your game. A sound is a WAV file that can be
played on command via the method play
. While some platforms may support MP3s, we
can only guarantee that WAVs work on all platforms. In order for Kivy to find a WAV
file, you should put it in the Sounds directory. Sounds in that folder can be
referenced directly by name.
When a sound is played, it cannot be played again until it finishes, or is stopped.
This means that if you want multiple, simultaneous sound effects from the same WAV
file you will need to create multiple Sound
objects.
Class Sound¶
This is the primary class. It represents a sounds that can be played.
Constructor¶
-
Sound
(source)¶ Creates a new sound from a file.
Parameter: source ( str
) – The string providing the name of a sound file
Class SoundLibrary¶
This class implements to the dictionary interface to make it easier to load sounds and manage them. To load a sound, simply assign it to the library object, as follows:
soundlib['soundname'] = 'soundfile.wav'
The sound library will load the sound and map it to 'soundname'
as the key.
To play the sound, we access it as follows:
soundlib['soundname'].play()