[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] toggle between play pause and unpause



Hello.
This is my first e-mail in this mailling list.
I've a project using python 2.7 and pygame. The problem is
I've a button when I press it the music played and when I press it again the music paused , but when I press the button in a third time the music does not unpause
Any help please and I'm so sorry for the mistakes in writing .

played = True

def holder():
    time.sleep(0.001)

def play(track):
    global played
    pygame.mixer.init()
    pygame.mixer.music.load(track)
    t = wx.PyTimer(holder)
    if played :
        pygame.mixer.music.play()
        played = False
    elif pygame.mixer.music.get_busy():
        pygame.mixer.music.pause()
    elif not pygame.mixer.music.get_busy():
        pygame.mixer.music.unpause()
    else:
        played = True
    t.Start(10)