pythonpygamesystem-error

Why is attempting to use pygame.mixer.Channel.play(Sound) raising a SystemError?


I've been having difficulty with getting Sound objects to play in my program; I received no error messages of any kind, the audio file itself is not broken, but every time I tried to run my program, no sound came out of my speakers. The first thing I tried was pygame.mixer.Sound.play() in order to play the sound, and when I didn't hear the sound, I double-checked to make sure the speakers on my computer were not muted, I turned the volume up higher, and I tried again. I still didn't hear it playing, so I tried creating a Channel object and telling the program to play the sound on that channel using the following code sample:

from time import sleep
from pygame import mixer
###
mixer.init() #initialize mixer module
#########
soundObj = mixer.Sound("mySound.wav") #create Sound object from .wav file
soundChn = mixer.Channel(0) #create Channel object to play sounds from
###
soundChn.play(soundObj, 0) #play soundObj on the channel once - ERROR IS HERE
sleep(soundObj.get_length()) #pause program for the duration of soundObj

When I ran my program in order to test whether or not this code worked, a traceback to soundChn.play(soundObj, 0) appeared, along with the error message SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer supported!

Can anyone explain to me--in the plainest English possible, please, because I am very confused--what exactly this error message means and what it is that I need to do in order to fix my problem? Thank you!


Solution

  • It looks like the version of pygame you've installed on your computer is an old version, using deprecated methods.

    As it seems to be working on my computer with both Python 2 & 3, I'd suggest to update pygame by running

    pip3 install --user pygame # or pip2 if using python2