August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)
In order to use the pygame mixer in a Kamaelia component there are a
couple of extra steps you need to take to make it initialize properly.
These are necessary so you can use the component in conjuction with the
various pygame UI components, which disable the mixer by default to
allow other sound sources to take control if they need to. The steps to
getting the mixer working are as follows.
If you call any pygame.mixer methods or objects in your component's
__init__() then you initialize the mixer by calling pygame.mixer.init().
Although you would expect this to keep the mixer initialized for the
main method in some instances this does not happen, so you also need to
make some small changes in your component's main method.
If you call any pygame.mixer methods of objects in your component's
main() method then you need to initialize the mixer a second (and
potentially third) time. This can be done by adding the following code
the the loop in your component's main method.
def main():
while 1: #This is your main loop
if not pygame.mixer.get_init():
pygame.mixer.init()
# You are safe to call pygame.mixer methods here
yield 1