changeset 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 9995931be5b1
children f56aeafb05b1
files vixm/control.py vixm/player.py vixm/playlist.py vixm/ui.py
diffstat 4 files changed, 30 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/vixm/control.py	Sat Nov 04 17:57:38 2006 -0500
+++ b/vixm/control.py	Sat Nov 04 23:11:49 2006 -0500
@@ -146,7 +146,7 @@
 def cmd_next(ui, start, stop, args):
 	"""b
 		- Direct XMMS control: next song"""
-	print "Next song not implemented"
+	ui.play.play_next(ui.lists)
 
 def cmd_shell(ui, start, stop, args):
 	"""![command]
--- a/vixm/player.py	Sat Nov 04 17:57:38 2006 -0500
+++ b/vixm/player.py	Sat Nov 04 23:11:49 2006 -0500
@@ -3,19 +3,38 @@
 
 import mad, ao
 
+import playlist
+
 class playerThread(Thread):
 	def __init__(self):
 		Thread.__init__(self)
 
 		self.shutdown = False
 		self.playing  = False
+		self.end_current = False
 
 		self.current  = None
 
 		self.blksize  = 40960
 		self.dev      = ao.AudioDevice("oss")
 
+	def play_next(self, lists):
+		try:
+			# pop song off the PRIO queue
+			s = lists[playlist.LIST_PRIO].pop()
+		except IndexError:
+			# no song to pop
+			s = lists[playlist.LIST_DEFAULT].next()
+		except ValueError:
+			print "WTF is going on?!"
+			raise ValueError
+
+		self.play(s)
+
 	def play(self, s):
+		if self.playing:
+			self.end_current = True
+
 		self.playing = True
 		self.current = s
 
@@ -27,10 +46,16 @@
 		
 				while True:
 					buf = mf.read(self.blksize)
-					if buf is None or self.shutdown:
+					if buf is None or \
+					   self.shutdown or \
+					   self.end_current:
 						break
 					self.dev.play(buf, len(buf))
-				self.playing = False
+
+				if self.end_current:
+					self.end_current = False
+				else:
+					self.playing = False
 			else:
 				# nothing to play, just sleep
 				time.sleep(0.5)
--- a/vixm/playlist.py	Sat Nov 04 17:57:38 2006 -0500
+++ b/vixm/playlist.py	Sat Nov 04 23:11:49 2006 -0500
@@ -15,7 +15,7 @@
 	def __init__(self, allowrandom=False):
 		self.__list = []
 		self.__allowrand = allowrandom # allow randomization of this list
-		self.__cursor = allowrandom and self.__rnd() or 0
+		self.__cursor = 0
 	
 	def enqueue(self, song):
 		""" Append a song to the list """
--- a/vixm/ui.py	Sat Nov 04 17:57:38 2006 -0500
+++ b/vixm/ui.py	Sat Nov 04 23:11:49 2006 -0500
@@ -44,17 +44,7 @@
 	while not play.shutdown:
 		# check which song we are playing now
 		if not play.playing:
-			try:
-				# pop song off the PRIO queue
-				next = lists[playlist.LIST_PRIO].pop()
-			except IndexError:
-				# no song to pop
-				next = lists[playlist.LIST_DEFAULT].next()
-				pass
-			except ValueError:
-				print "WTF is going on?!"
-
-			play.play(next)
+			play.play_next(lists)
 
 		# sleep
 		time.sleep(0.5)