I'm using StringIO to stream music data, but it appears that when I run with pygame.mixer.music.load(), my application won't exit. Even if I use close():
def PlaySong(self, song_id):
song = StringIO.StringIO(resp.read())
self.pygame.mixer.music.load(song)
....
The function will return, but the application has to be killed. If I save the response to a file, then load the filename, it will close. Can anybody help? I don't want to use local storage.
More info. I did a strace on both opening from a file, and using stringio, strace will exit properly for both instances. The straces look clean.
Working code:
def playsong():
mp3 = "/home/adam/Documents/pinyin/pinyinchart_win/pinyin/zuo2.mp3"
#with open(mp3, "rb") as outfile:
# song = outfile.read()
#io = StringIO.StringIO(song)
pygame.init()
pygame.mixer.music.load(mp3)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(50)
#io.close()
#outfile.close()
Not working code:
def playsong():
mp3 = "/home/adam/Documents/pinyin/pinyinchart_win/pinyin/zuo2.mp3"
with open(mp3, "rb") as outfile:
song = outfile.read()
io = StringIO.StringIO(song)
pygame.init()
#pygame.mixer.music.load(io)
pygame.mixer.music.load(mp3)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(50)
io.close()
outfile.close()