diff 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 diff
--- a/vixm/player.py	Fri Nov 03 23:59:10 2006 -0500
+++ b/vixm/player.py	Sat Nov 04 15:31:32 2006 -0500
@@ -12,23 +12,26 @@
 
 		self.current  = None
 
+		self.blksize  = 40960
 		self.dev      = ao.AudioDevice("oss")
 
 	def play(self, s):
 		self.playing = True
 		self.current = s
 
-		mf = mad.MadFile(s["file"])
-
-		while True:
-			buf = mf.read()
-			if buf is None:
-				break
-			self.dev.play(buf, len(buf))
-
-		self.playing = False
-
 	def run(self):
 		while not self.shutdown:
-			time.sleep(0.5)
+			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)