According to the pygame documentation, pygame.mixer.Sound().play() should return a Channel object. It actually does.
But sometimes, it seems to return None because the very next line, I get this error:
NoneType has no attribute set_volume
when I try to type
channel = music.play(-1)
channel.set_volume(0.5)
Of course the error can happen because the sound is very short, but the error can't come from there (Is 5'38" shorter than the time python needs to shift from one line to the next?)
I also Ctrl+H all the code to see if I typed somewhere channel = None (because I use multiple threads) - Nothing.
Does anybody had the same problem? Is that a pygame bug?
I use python 3.8.2, pygame 2.0.1 and Windows.
Currently I bypass the error rather than fix it like that:
channel = None
while channel is None:
channel = music.play()
channel.set_volume(0.5)
But... it doesn't seem to help very much: the game freezes, because pygame constantly returns None.