Fixed finding duration

git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@6 1daee41c-8060-4895-b1f0-2197c00d777a
This commit is contained in:
bjschuma 2009-05-31 23:43:01 +00:00
parent 068de4a7ee
commit 7e0bb34e8d
3 changed files with 17 additions and 16 deletions

View File

@ -94,6 +94,7 @@ class Library():
indices = set(self.data.map[words[0]])
for word in words[1:]:
indices = indices & set(self.data.map[word])
if len(indices) == 1:
return indices.pop()
# Return first instance
if len(indices) > 0:
return indices.pop()
return -1

View File

@ -23,18 +23,18 @@ class main:
self.song = None
# If we were given a song as input, check that it exists and begin playback
if len(argv) > 0:
file = os.path.expanduser(argv[0])
if os.path.exists(file) == True:
split = file.split(self.library.data.path)
file = split[len(split)-1]
index = self.library.has(file)
info = None
if index != -1:
info = self.library.data.files[index]
else:
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:
file = os.path.expanduser(argv[0])
if os.path.exists(file):
info = SongInfo()
info.filename = file
#se
if info != None:
self.song = Song(info,self.quit,self.commands.printLines)
self.song.play()
@ -80,7 +80,7 @@ class main:
if self.song == None:
return
cur = self.song.curTime()
tot = self.song.length
tot = self.song.info.length
self.commands.printLine(cur.toStr()+" / "+tot.toStr())
# Show detailed song info

View File

@ -56,9 +56,9 @@ class Song():
def play(self):
self.player.set_state(gst.STATE_PLAYING)
# Start main loop and find duration (if this hasn't been done yet)
#if self.info.length == None:
# time.sleep(0.5)
# self.duration()
if self.info.length == None:
time.sleep(0.5)
self.duration()
# Change state to "paused"