[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] toggle between play pause and unpause
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] toggle between play pause and unpause
- From: Sam Bull <sam.hacking@xxxxxxxx>
- Date: Sun, 07 May 2017 20:42:29 +0100
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Sun, 07 May 2017 15:49:00 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h= content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=jH15VwxIK7Gf6/aDhne7McedflGIdqw0MkrwvIvP0 kc=; b=lGpu/mvbKqCmpXSUXo89z3S1astyEy69/UaPBmvJnyA65AXlGrLx1E3/0 66syHCuGUKKfKOWOyF4dFMdNlxzXCbYTvPkeYV++pIZQFFb5ZT7LKesvwkhfP1WI 5g+zVBXlPP3iihcY7EGELNr3u5UETk8r6laoXUcF2grDPWsmGr1WfUN1O8UxbYMm lXKvXh/6lHRdymzYiAXbRDlTJGU5D9ypQ1nCBHwm5ldlRKsmoWOgeqmel0aNDtC6 STYecw84sREsgJAKHaswsFWuIfigL5m3Z+oT+sTsyYODbjQu2II9IKSzkkzpui9F 9Rm2ezEHoYh4mq8ceqMhhyPE8oizw==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=jH15VwxIK7Gf6/aDhn e7McedflGIdqw0MkrwvIvP0kc=; b=cQh3SsHzaWzsMGOf3gHQmsPmKbOH9MH9zs /fJ/cidkElsGNVDiRNiCaO6J1I8CudinyS4vuTvCsDhalwewRaTX7YjIKA5cP+Ys T01ylEL8VFJdM/qAL49hRtQ2/WtzCBcUNkUWT846JWpXHmb+4LJyO5/sCSiLdK3c RH3Gy3FXQyzTgzty4u/gfFxZA1+c5qNU1icQSNcFeIXpj+ZUL4dGDz8UlCV2m8rQ jfGPwI/9cp0US3G9dQEn1vPspTRzcLW/9QGGqXBIxNAMuRk+4oIYgrPMrJTG7C1Z cy0yV3oKL2GvpkHdzH9lEwQUVi/mJeQDIYLqSAQBfZJ0kiBY+rNA==
- In-reply-to: <590F5AA3.70107@gmail.com>
- References: <590F5AA3.70107@gmail.com>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
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)
Attachment:
signature.asc
Description: This is a digitally signed message part