Mercurial > vixm
comparison 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 |
comparison
equal
deleted
inserted
replaced
36:c6a3a4d09a9a | 37:87aa31e41f4a |
---|---|
10 self.shutdown = False | 10 self.shutdown = False |
11 self.playing = False | 11 self.playing = False |
12 | 12 |
13 self.current = None | 13 self.current = None |
14 | 14 |
15 self.blksize = 40960 | |
15 self.dev = ao.AudioDevice("oss") | 16 self.dev = ao.AudioDevice("oss") |
16 | 17 |
17 def play(self, s): | 18 def play(self, s): |
18 self.playing = True | 19 self.playing = True |
19 self.current = s | 20 self.current = s |
20 | 21 |
21 mf = mad.MadFile(s["file"]) | |
22 | |
23 while True: | |
24 buf = mf.read() | |
25 if buf is None: | |
26 break | |
27 self.dev.play(buf, len(buf)) | |
28 | |
29 self.playing = False | |
30 | |
31 def run(self): | 22 def run(self): |
32 while not self.shutdown: | 23 while not self.shutdown: |
33 time.sleep(0.5) | 24 if self.current and self.playing: |
25 # play the file | |
26 mf = mad.MadFile(self.current["file"]) | |
27 | |
28 while True: | |
29 buf = mf.read(self.blksize) | |
30 if buf is None or self.shutdown: | |
31 break | |
32 self.dev.play(buf, len(buf)) | |
33 self.playing = False | |
34 else: | |
35 # nothing to play, just sleep | |
36 time.sleep(0.5) | |
34 | 37 |