pytho...@gmail.com wrote:
>
> I want to make the onPlay() method to do playing and pausing and
> resume playing after pausing and replay after finishing playing all in
> one button
> so in the first click on the play button the song start playing.
> in the second click the song pause and in the third click the song
> resume playing
> and after finish playing when I click the play button the song start
> again , how can I do it.
Just ask yourself, if I as a human being were asked to do this task,
knowing only what the computer knows, how would I do it? As Rufus said,
you need some way to keep track of what your current "state" is. Then,
in your button click handler, you just need to make the changes
necessary to move from one state to another.
As a crude example:
IDLE, PLAYING, PAUSED = range(3)
def __init__(...)
state = IDLE
def onButtonClick(...):
if state == IDLE:
# Do whatever is necessary to start playing
state = PLAYING
elif state == PLAYING:
# Tell the media control to pause playback
state = PAUSED
elif state == PAUSED:
# Tell the media control to resume playback
state = PLAYING
When handling an event, you just need to think "what information do I
have that can help me get from where I am to where I need to be?"