comparison vixm/player.py @ 40:06b5a7db3d19 pure

Some cleanup, got to next song implemented
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Sat, 04 Nov 2006 23:11:49 -0500
parents 87aa31e41f4a
children bc6db55448e1
comparison
equal deleted inserted replaced
39:9995931be5b1 40:06b5a7db3d19
1 import time 1 import time
2 from threading import Thread 2 from threading import Thread
3 3
4 import mad, ao 4 import mad, ao
5
6 import playlist
5 7
6 class playerThread(Thread): 8 class playerThread(Thread):
7 def __init__(self): 9 def __init__(self):
8 Thread.__init__(self) 10 Thread.__init__(self)
9 11
10 self.shutdown = False 12 self.shutdown = False
11 self.playing = False 13 self.playing = False
14 self.end_current = False
12 15
13 self.current = None 16 self.current = None
14 17
15 self.blksize = 40960 18 self.blksize = 40960
16 self.dev = ao.AudioDevice("oss") 19 self.dev = ao.AudioDevice("oss")
17 20
21 def play_next(self, lists):
22 try:
23 # pop song off the PRIO queue
24 s = lists[playlist.LIST_PRIO].pop()
25 except IndexError:
26 # no song to pop
27 s = lists[playlist.LIST_DEFAULT].next()
28 except ValueError:
29 print "WTF is going on?!"
30 raise ValueError
31
32 self.play(s)
33
18 def play(self, s): 34 def play(self, s):
35 if self.playing:
36 self.end_current = True
37
19 self.playing = True 38 self.playing = True
20 self.current = s 39 self.current = s
21 40
22 def run(self): 41 def run(self):
23 while not self.shutdown: 42 while not self.shutdown:
25 # play the file 44 # play the file
26 mf = mad.MadFile(self.current["file"]) 45 mf = mad.MadFile(self.current["file"])
27 46
28 while True: 47 while True:
29 buf = mf.read(self.blksize) 48 buf = mf.read(self.blksize)
30 if buf is None or self.shutdown: 49 if buf is None or \
50 self.shutdown or \
51 self.end_current:
31 break 52 break
32 self.dev.play(buf, len(buf)) 53 self.dev.play(buf, len(buf))
33 self.playing = False 54
55 if self.end_current:
56 self.end_current = False
57 else:
58 self.playing = False
34 else: 59 else:
35 # nothing to play, just sleep 60 # nothing to play, just sleep
36 time.sleep(0.5) 61 time.sleep(0.5)
37 62