From 64635c17ddbad78cdf4ffbdf4d1d446dc703fa73 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Mon, 1 Jun 2009 01:13:30 +0000 Subject: [PATCH] Can play other songs after the first ends git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@8 1daee41c-8060-4895-b1f0-2197c00d777a --- trunk/library.py | 8 ++++++++ trunk/ocarina.py | 37 +++++++++++++++++++++++++++++-------- trunk/playlist.py | 30 ++++++++++++++++++++++++++++-- trunk/song.py | 4 ++++ 4 files changed, 69 insertions(+), 10 deletions(-) diff --git a/trunk/library.py b/trunk/library.py index a251ac42..fdd33119 100644 --- a/trunk/library.py +++ b/trunk/library.py @@ -98,3 +98,11 @@ class Library(): if len(indices) > 0: return indices.pop() return -1 + + + def nonBanned(self): + list = [] + for i in range(len(self.data.files)): + if self.data.files[i].banned == False: + list += [i] + return list diff --git a/trunk/ocarina.py b/trunk/ocarina.py index e2e70866..0a6e58f2 100644 --- a/trunk/ocarina.py +++ b/trunk/ocarina.py @@ -7,6 +7,7 @@ from song import Song from cline import CLine from duration import Duration from library import Library +from playlist import Playlist from songInfo import SongInfo #import cmnds @@ -19,6 +20,8 @@ class main: self.registerCmnds() self.library = Library(self.commands.printLines) + self.plist = Playlist(self.commands.printLines) + self.plist.insert(self.library.nonBanned()) self.song = None # If we were given a song as input, check that it exists and begin playback @@ -26,18 +29,24 @@ class main: split = argv[0].split(self.library.data.path) if len(split) > 0: index = self.library.has(split[len(split)-1]) - info = None - if index != -1: - info = self.library.data.files[index] - else: + #if index != -1: + #info = self.library.data.files[index] + self.plist.queueSong(index) + if index==-1: file = os.path.expanduser(argv[0]) if os.path.exists(file): info = SongInfo() info.filename = file - if info != None: - self.song = Song(info,self.quit,self.commands.printLines) - self.song.play() - + self.song = Song(info,self.next,self.commands.printLines) + self.next("") + #if info != None: + #self.plist.queueSong(info) + #self.song = Song(info,self.next,self.commands.printLines) + #self.plist.queueSong(-1) + #self.next("") + #self.song = Song(info,self.quit,self.commands.printLines) + #self.song.play() + # self.commands.printLine(str(self.song)) # Start main loop as a thread so we can get bus calls and use command line gobject.threads_init() @@ -55,6 +64,7 @@ class main: self.commands.register("info",self.info,"Display detailed info about current song") self.commands.register("this",self.this,"Display basic info about current song") self.commands.register("lib",self.scanLib,"Create a library based on the directory passed in") + self.commands.register("next",self.next,"Advance to the next song") # Quit program def quit(self,unused): @@ -116,4 +126,15 @@ class main: return self.library.scan(dir) + + def next(self,unused): + if self.song != None: + self.song.close() + index = self.plist.next() + if index != -1: + self.song = None + info = self.library.data.files[index] + self.song = Song(info,self.next,self.commands.printLines) + self.song.play() + if __name__=='__main__':main(sys.argv[1:]) diff --git a/trunk/playlist.py b/trunk/playlist.py index d24af2dc..2f2fd81c 100644 --- a/trunk/playlist.py +++ b/trunk/playlist.py @@ -1,4 +1,30 @@ +import Queue class Playlist: - def __init__(self): - print "Creating Playlist" + def __init__(self,prnt): + self.prnt = prnt + self.list = [] + self.queue = Queue.Queue() + self.curSong = 0 + + + # Enqueue a song + # Takes songInfo! + 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() + song = self.list[self.curSong] + self.curSong += 1 + if self.curSong > len(self.list): + self.curSong = 0 + return song diff --git a/trunk/song.py b/trunk/song.py index b73a75d3..70fda267 100644 --- a/trunk/song.py +++ b/trunk/song.py @@ -66,6 +66,10 @@ class Song(): self.player.set_state(gst.STATE_PAUSED) + def close(self): + self.player.set_state(gst.STATE_NULL) + + # Find the duration of the pipeline def duration(self): self.info.length = Duration()