changeset 39:9995931be5b1 pure

Select first song randomly if needed
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Sat, 04 Nov 2006 17:57:38 -0500
parents 411eb70448be
children 06b5a7db3d19
files vixm/playlist.py
diffstat 1 files changed, 5 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/vixm/playlist.py	Sat Nov 04 15:43:35 2006 -0500
+++ b/vixm/playlist.py	Sat Nov 04 17:57:38 2006 -0500
@@ -15,7 +15,7 @@
 	def __init__(self, allowrandom=False):
 		self.__list = []
 		self.__allowrand = allowrandom # allow randomization of this list
-		self.__cursor = 0
+		self.__cursor = allowrandom and self.__rnd() or 0
 	
 	def enqueue(self, song):
 		""" Append a song to the list """
@@ -29,13 +29,11 @@
 		""" Pop the next song """
 		return self.__list.pop(0)
 
+	def __rnd(self):
+		return random.randint(0, len(self.__list)-1)
+
 	def next(self):
 		""" Get the next song """
-		def rnd():
-			return random.randint(0, len(self.__list)-1)
-
-		##
-
 		idx = self.__cursor
 
 		if not self.__allowrand:
@@ -43,7 +41,7 @@
 			if self.__cursor >= len(self.__list):
 				self.__cursor = 0
 		else:
-			self.__cursor = rnd()
+			self.__cursor = self.__rnd()
 
 		return self.__list[idx]