python pygame question
i'm trying to make my own media player, but i have a problem. i can't allow the user to input (play, pause, stop, etc) and make it so it automatically plays the next song when one ends. if i put it in a while loop i can make it play one song after another, but then i can't have any user input. the only way i can see to do it is to create my own event which would be triggered when a song ends, but i can't find anything helpful on google. can anyone help me with this?
this is what i originally had, but it just sits and waits for the user input, so if it gets to the end of a song it waits. i added the pygame.mixer.music.queue which will make it play the next song, but after that it stops unless you input another command.
def GetSong(musicList, x):
if not pygame.mixer.music.get_busy():
pygame.mixer.music.load(musicList[x])
pygame.mixer.music.play()
else:
pygame.mixer.music.stop()
pygame.mixer.music.load(musicList[x])
pygame.mixer.music.play()
def Stop():
pygame.mixer.music.stop()
def Pause():
pygame.mixer.music.pause()
def Resume():
pygame.mixer.music.unpause()
while 1:
command=raw_input('Whatcha wanna do?: ')
if command=="play":
GetSong(musicList, x)
if command=="stop":
Stop()
if command=="pause":
Pause()
if command=="resume":
Resume()
if command=="skip":
if x<len(musicList)-1:
x+=1
GetSong(musicList, x)
else:
x=0
GetSong(musicList, x)
if pygame.mixer.music.get_busy():
if x<len(musicList)-1:
x+=1
else:
x=0
pygame.mixer.music.queue(musicList[x])
i tried switching to a key listener with tkinter frames, but the only way it'll move on to the next song is if i make an event and bind it to the frame or maybe threading(which i also couldnt find any help on)
reaper4334 is right.
You need to run it from the commandline. lots of things dont work right in idle.
GUI and espace chars (\b, etc)
this is because idle itself is coded in python and uses the eval() function to run the code.
use idle as an IDE and run it at command line… i do this anyways.. just makes for a better testbed
okay, i got msvcrt.getch() to work, but now i'm back where i started cuz the interpreter still sits there and waits for key input when i call up msvcrt.getch(). so does anyone know if there's a simple way to just check to see if the keyboard gets used, that way i can just call up getch() only if someone types something on the keyboard