On Sun, 2017-05-07 at 13:41 -0700, pythonis...@gmail.com wrote: > Thank you for your reply. But nothing changed . > the else block did not run .
This is where you need to do a little debugging on your own. Add a print(started, playing) line into the play function and view what state it is at each time you press the button, the output I would expect to see from the first few clicks would be: False False True True True False True True If that is the output you see, then the else block should be running. You can test that by adding a print("FOO") line in the else block and seeing if it runs on the 3rd button press. > def play(track): > global playing, started > pygame.mixer.init() > pygame.mixer.music.load(track) > t = wx.PyTimer(holder) > if not started : > pygame.mixer.music.play() > playing = True > started = True > elif playing: > pygame.mixer.music.pause() > playing = False > else: > paused() > playing = True > t.Start(10) > > > > > From the comments on the docs page: > > > > Yes, I've got the same problem. It only returns false when the > > music > > has been stopped, or no music has been loaded. > > Maybe there should be an is_paused() method... > > http://www.pygame.org/docs/ref/music.html#comment_pygame_mixer_ > > music > > _get_busy > > > > So, don't switch on get_busy(), perhaps just keep a record of the > > button state. > > > > e.g. > > > > if not started: > > pygame.mixer.music.play() > > started = True > > playing = True > > elif playing: > > pygame.mixer.music.pause() > > playing = False > > else: > > pygame.mixer.music.unpause() > > playing = True > > > > > > Perhaps also using set_endevent() to monitor when it has finished > > playing, and reset started to False. > > > > > > Note that in your original code, the else part is unlikely to ever > > run. > > > > > > On Sun, 2017-05-07 at 18:34 +0100, toufik wrote: > > > 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)
signature.asc
Description: This is a digitally signed message part