我使用下面的代码在python中使用pygame库播放一首歌曲。它播放歌曲,如果我直接点击python文件,我可以听到声音。但是如果我用python(命令行)或python(GUI)运行程序,我就听不到声音。我检查了python2.6和2.7。我使用的是Windows7操作系统。在
我的代码:import pygame,time,sys
pygame.init()
pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
print "Mixer settings", pygame.mixer.get_init()
print "Mixer channels", pygame.mixer.get_num_channels()
pygame.mixer.music.set_volume(1.0)
pygame.mixer.music.load("2.mp3")
while 1:
selection = raw_input()
if selection == "play":
print "Playing"
pygame.mixer.music.play()
elif selection == "rewind":
pygame.mixer.music.rewind()
elif selection == "pause":
pygame.mixer.music.pause()
elif selection == "stop":
pygame.mixer.music.stop()
elif selection == "queue":
inputqueue = raw_input()
pygame.mixer.music.queue(inputqueue)
else:
print "invalid selection"
sys.stdout.flush()