Answer the question
In order to leave comments, you need to log in
How to track if a song is currently playing in pygame?
Good afternoon! I work with pygame. I want it to keep track of whether the music (played by pygame) is currently playing. So that it can be used in an if.
Answer the question
In order to leave comments, you need to log in
I assume that you need to track the moment when the melody playback is completed.
In this case, it is better to use custom events.
For example.
In the part of the code where the initial initialization takes place:
pygame.mixer.init()
STOPPED_PLAYING = pygame.USEREVENT + 1
pygame.mixer.music.set_endevent(STOPPED_PLAYING)
for event in pygame.event.get():
if STOPPED_PLAYING == event.type:
# код для выполнения при окончании воспроизведения музыки
# например выбор и начало воспроизведения следующей мелодии
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question