ocarina/trunk/playlist.py

39 lines
701 B
Python

import Queue
import random
class Playlist:
#def __init__(self,prnt):
def __init__(self):
#self.prnt = prnt
self.list = []
self.queue = Queue.Queue()
self.curSong = 0
self.random = True
# Enqueue a song
# Takes songid
def queueSong(self,song):
self.queue.put(song)
# Insert the list of songs
def insert(self,list):
self.list = list
# Return the next song
def next(self):
if self.queue.empty() == False:
return self.queue.get()
if len(self.list) == 0:
return -2
if self.random==True:
self.curSong = random.randint(0,len(self.list)-1)
song = self.list[self.curSong]
self.curSong += 1
if self.curSong > len(self.list):
self.curSong = 0
return song