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
This commit is contained in:
bjschuma 2009-06-01 01:13:30 +00:00
parent e1a61cd711
commit 64635c17dd
4 changed files with 69 additions and 10 deletions

View File

@ -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

View File

@ -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:])

View File

@ -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

View File

@ -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()