Mercurial > vixm
view vixm/player.py @ 37:87aa31e41f4a master
Play the files in a separate thread
author | Josef "Jeff" Sipek <jeffpc@josefsipek.net> |
---|---|
date | Sat, 04 Nov 2006 15:31:32 -0500 |
parents | c6a3a4d09a9a |
children | 06b5a7db3d19 |
line wrap: on
line source
import time from threading import Thread import mad, ao class playerThread(Thread): def __init__(self): Thread.__init__(self) self.shutdown = False self.playing = False self.current = None self.blksize = 40960 self.dev = ao.AudioDevice("oss") def play(self, s): self.playing = True self.current = s def run(self): while not self.shutdown: if self.current and self.playing: # play the file mf = mad.MadFile(self.current["file"]) while True: buf = mf.read(self.blksize) if buf is None or self.shutdown: break self.dev.play(buf, len(buf)) self.playing = False else: # nothing to play, just sleep time.sleep(0.5)