![]() |
A loop inside a function or how to design a Play/Stop button
Hi,
I've been stuck on the following for quite some time now so any help is GREATLY appreciated :) I'm trying to create a Play/Pause button: Ive already got the play part sorted but I cant seem to get the looping part right! My program will play the song when the "Play" button is played. Im trying to set up a loop that detect if the song is playing and it it is, it will pause it, if not, it will resume it. Here's the code: Code:
As you can see, im quite stuck. Does anyone have an idea? Should I consider nested loops? Or maybe assign 2 Slots for 1 signal? |
Re: A loop inside a function or how to design a Play/Stop button
I'm no Python buff, but white space is very important. In your pauseSong method, you've got an extra space on the second if-statement line.
This will give the parser trouble. |
Re: A loop inside a function or how to design a Play/Stop button
and dont forget to set the pause=false after the second if.
|
Re: A loop inside a function or how to design a Play/Stop button
Quote:
Quote:
ANyways, thanks for the input guys! :) |
Re: A loop inside a function or how to design a Play/Stop button
I'm no Python person, but shouldn't "playing" be a global?
|
Re: A loop inside a function or how to design a Play/Stop button
Add a print before pygame.mixer.pause() to see if your IFs work as expected ;)
|
Re: A loop inside a function or how to design a Play/Stop button
doesnt the python mixer have get_busy() method which can be used to check if things are in use?
pseudocode: if pygame.mixer.get_busy() python.mixer.pause() else python.mixer.unpause() certainly sounds more feasible to me, but there might be a reason you cannot use similar you shouldn't need to retain the state - technically it should come from each channel/the mixer |
Re: A loop inside a function or how to design a Play/Stop button
Quote:
ooo i like the pygame stuff :D - just been having a read-up :D http://www.pygame.org/docs/ref/mixer.html EL Amir - take a look at these ones :D http://code.activestate.com/recipes/...ss-platform-m/ |
Re: A loop inside a function or how to design a Play/Stop button
Quote:
It should be "paused = False" but at the moment you have "pause = False" Code:
#initial conditions Code:
#Starts the playback of the song Would it not make more sense for the "pauseSong()" definition to execute "song.pause()" as opposed to "pygame.mixer.pause()"? I'm not familiar with the mixer class so please correct me :) |
Re: A loop inside a function or how to design a Play/Stop button
Quote:
|
All times are GMT. The time now is 07:03. |
vBulletin® Version 3.8.8