Mercurial > vixm
annotate 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 
rev  line source 

30
860c891de6bb
Remove lots of xmmsrelated code & get ready to make the whole program a
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

1 import time 
860c891de6bb
Remove lots of xmmsrelated code & get ready to make the whole program a
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

2 from threading import Thread 
860c891de6bb
Remove lots of xmmsrelated code & get ready to make the whole program a
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

3 
35
a7d370f326df
Implement song playing
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
34
diff
changeset

4 import mad, ao 
a7d370f326df
Implement song playing
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
34
diff
changeset

5 
40
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

6 import playlist 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

7 
30
860c891de6bb
Remove lots of xmmsrelated code & get ready to make the whole program a
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

8 class playerThread(Thread): 
35
a7d370f326df
Implement song playing
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
34
diff
changeset

9 def __init__(self): 
30
860c891de6bb
Remove lots of xmmsrelated code & get ready to make the whole program a
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

10 Thread.__init__(self) 
860c891de6bb
Remove lots of xmmsrelated code & get ready to make the whole program a
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

11 
860c891de6bb
Remove lots of xmmsrelated code & get ready to make the whole program a
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

12 self.shutdown = False 
32
f97eb9f0c207
Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
30
diff
changeset

13 self.playing = False 
40
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

14 self.end_current = False 
32
f97eb9f0c207
Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
30
diff
changeset

15 
34
8028f2addb00
Destroy all traces of xmms
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
32
diff
changeset

16 self.current = None 
30
860c891de6bb
Remove lots of xmmsrelated code & get ready to make the whole program a
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

17 
37
87aa31e41f4a
Play the files in a separate thread
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
36
diff
changeset

18 self.blksize = 40960 
36
c6a3a4d09a9a
Small fix & change output to OSS
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
35
diff
changeset

19 self.dev = ao.AudioDevice("oss") 
30
860c891de6bb
Remove lots of xmmsrelated code & get ready to make the whole program a
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

20 
40
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

21 def play_next(self, lists): 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

22 try: 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

23 # pop song off the PRIO queue 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

24 s = lists[playlist.LIST_PRIO].pop() 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

25 except IndexError: 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

26 # no song to pop 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

27 s = lists[playlist.LIST_DEFAULT].next() 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

28 except ValueError: 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

29 print "WTF is going on?!" 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

30 raise ValueError 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

31 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

32 self.play(s) 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

33 
32
f97eb9f0c207
Add random song selection for default queue
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
30
diff
changeset

34 def play(self, s): 
40
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

35 if self.playing: 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

36 self.end_current = True 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

37 
35
a7d370f326df
Implement song playing
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
34
diff
changeset

38 self.playing = True 
a7d370f326df
Implement song playing
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
34
diff
changeset

39 self.current = s 
a7d370f326df
Implement song playing
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
34
diff
changeset

40 
30
860c891de6bb
Remove lots of xmmsrelated code & get ready to make the whole program a
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

41 def run(self): 
860c891de6bb
Remove lots of xmmsrelated code & get ready to make the whole program a
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

42 while not self.shutdown: 
37
87aa31e41f4a
Play the files in a separate thread
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
36
diff
changeset

43 if self.current and self.playing: 
87aa31e41f4a
Play the files in a separate thread
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
36
diff
changeset

44 # play the file 
87aa31e41f4a
Play the files in a separate thread
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
36
diff
changeset

45 mf = mad.MadFile(self.current["file"]) 
87aa31e41f4a
Play the files in a separate thread
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
36
diff
changeset

46 
87aa31e41f4a
Play the files in a separate thread
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
36
diff
changeset

47 while True: 
87aa31e41f4a
Play the files in a separate thread
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
36
diff
changeset

48 buf = mf.read(self.blksize) 
40
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

49 if buf is None or \ 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

50 self.shutdown or \ 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

51 self.end_current: 
37
87aa31e41f4a
Play the files in a separate thread
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
36
diff
changeset

52 break 
87aa31e41f4a
Play the files in a separate thread
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
36
diff
changeset

53 self.dev.play(buf, len(buf)) 
40
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

54 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

55 if self.end_current: 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

56 self.end_current = False 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

57 else: 
06b5a7db3d19
Some cleanup, got to next song implemented
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
37
diff
changeset

58 self.playing = False 
37
87aa31e41f4a
Play the files in a separate thread
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
36
diff
changeset

59 else: 
87aa31e41f4a
Play the files in a separate thread
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
36
diff
changeset

60 # nothing to play, just sleep 
87aa31e41f4a
Play the files in a separate thread
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
36
diff
changeset

61 time.sleep(0.5) 
30
860c891de6bb
Remove lots of xmmsrelated code & get ready to make the whole program a
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

62 