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:
parent
e1a61cd711
commit
64635c17dd
|
@ -98,3 +98,11 @@ class Library():
|
||||||
if len(indices) > 0:
|
if len(indices) > 0:
|
||||||
return indices.pop()
|
return indices.pop()
|
||||||
return -1
|
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
|
||||||
|
|
|
@ -7,6 +7,7 @@ from song import Song
|
||||||
from cline import CLine
|
from cline import CLine
|
||||||
from duration import Duration
|
from duration import Duration
|
||||||
from library import Library
|
from library import Library
|
||||||
|
from playlist import Playlist
|
||||||
from songInfo import SongInfo
|
from songInfo import SongInfo
|
||||||
#import cmnds
|
#import cmnds
|
||||||
|
|
||||||
|
@ -19,6 +20,8 @@ class main:
|
||||||
self.registerCmnds()
|
self.registerCmnds()
|
||||||
|
|
||||||
self.library = Library(self.commands.printLines)
|
self.library = Library(self.commands.printLines)
|
||||||
|
self.plist = Playlist(self.commands.printLines)
|
||||||
|
self.plist.insert(self.library.nonBanned())
|
||||||
|
|
||||||
self.song = None
|
self.song = None
|
||||||
# If we were given a song as input, check that it exists and begin playback
|
# 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)
|
split = argv[0].split(self.library.data.path)
|
||||||
if len(split) > 0:
|
if len(split) > 0:
|
||||||
index = self.library.has(split[len(split)-1])
|
index = self.library.has(split[len(split)-1])
|
||||||
info = None
|
#if index != -1:
|
||||||
if index != -1:
|
#info = self.library.data.files[index]
|
||||||
info = self.library.data.files[index]
|
self.plist.queueSong(index)
|
||||||
else:
|
if index==-1:
|
||||||
file = os.path.expanduser(argv[0])
|
file = os.path.expanduser(argv[0])
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
info = SongInfo()
|
info = SongInfo()
|
||||||
info.filename = file
|
info.filename = file
|
||||||
if info != None:
|
self.song = Song(info,self.next,self.commands.printLines)
|
||||||
self.song = Song(info,self.quit,self.commands.printLines)
|
self.next("")
|
||||||
self.song.play()
|
#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
|
# Start main loop as a thread so we can get bus calls and use command line
|
||||||
gobject.threads_init()
|
gobject.threads_init()
|
||||||
|
@ -55,6 +64,7 @@ class main:
|
||||||
self.commands.register("info",self.info,"Display detailed info about current song")
|
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("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("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
|
# Quit program
|
||||||
def quit(self,unused):
|
def quit(self,unused):
|
||||||
|
@ -116,4 +126,15 @@ class main:
|
||||||
return
|
return
|
||||||
self.library.scan(dir)
|
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:])
|
if __name__=='__main__':main(sys.argv[1:])
|
||||||
|
|
|
@ -1,4 +1,30 @@
|
||||||
|
import Queue
|
||||||
|
|
||||||
class Playlist:
|
class Playlist:
|
||||||
def __init__(self):
|
def __init__(self,prnt):
|
||||||
print "Creating Playlist"
|
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
|
||||||
|
|
|
@ -66,6 +66,10 @@ class Song():
|
||||||
self.player.set_state(gst.STATE_PAUSED)
|
self.player.set_state(gst.STATE_PAUSED)
|
||||||
|
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.player.set_state(gst.STATE_NULL)
|
||||||
|
|
||||||
|
|
||||||
# Find the duration of the pipeline
|
# Find the duration of the pipeline
|
||||||
def duration(self):
|
def duration(self):
|
||||||
self.info.length = Duration()
|
self.info.length = Duration()
|
||||||
|
|
Loading…
Reference in New Issue