Keep trying to find duration until success
git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@14 1daee41c-8060-4895-b1f0-2197c00d777a
This commit is contained in:
parent
57be9b2599
commit
42b4b48d84
|
@ -71,7 +71,7 @@ class main:
|
|||
self.pauseButton = self.makeButton("pauseButton","images/pause.png",None,self.ops.pause)
|
||||
self.nextButton = self.makeButton("nextButton","images/next.png",None,self.ops.next)
|
||||
self.thisButton = self.makeButton("thisButton",None,"This",self.this)
|
||||
self.infoButton = self.makeButton("infoButton",None,"Info",self.info)
|
||||
self.infoButton = self.makeButton("infoButton",None,"Info",self.ops.info)
|
||||
# Add buttons to window
|
||||
self.inside.pack_start(self.playButton,False,False,0)
|
||||
self.inside.pack_start(self.pauseButton,False,False,0)
|
||||
|
@ -136,17 +136,17 @@ class main:
|
|||
self.commands.printLine(cur.toStr()+" / "+tot.toStr())
|
||||
|
||||
# Show detailed song info
|
||||
def info(self,widget,data):
|
||||
# Return if no song found
|
||||
if self.song == None:
|
||||
return
|
||||
# Return if no tags found
|
||||
if self.song.info.tags == None:
|
||||
print "Could not find any tags"
|
||||
return
|
||||
for tag in self.song.info.tags.keys():
|
||||
print tag+":",self.song.info.tags[tag]
|
||||
print self.song.info.filename
|
||||
#def info(self,widget,data):
|
||||
# # Return if no song found
|
||||
# if self.song == None:
|
||||
# return
|
||||
# # Return if no tags found
|
||||
# if self.song.info.tags == None:
|
||||
# print "Could not find any tags"
|
||||
# return
|
||||
# for tag in self.song.info.tags.keys():
|
||||
# print tag+":",self.song.info.tags[tag]
|
||||
# print self.song.info.filename
|
||||
|
||||
# Show basic song info
|
||||
#def this(self,unused):
|
||||
|
|
|
@ -43,3 +43,17 @@ class Operations:
|
|||
widget.set_fraction(float(self.song.current)/float(self.song.total))
|
||||
#print float(self.song.current)/float(self.song.total)
|
||||
return True
|
||||
|
||||
|
||||
# Print detailed song info
|
||||
def info(self,widget,data):
|
||||
# Return if no song found
|
||||
if self.song == None:
|
||||
return
|
||||
# Return if no tags found
|
||||
if self.song.info.tags == None:
|
||||
print "Could not find any tags"
|
||||
return
|
||||
for tag in self.song.info.tags.keys():
|
||||
print tag+":",self.song.info.tags[tag]
|
||||
print self.song.info.filename
|
||||
|
|
|
@ -12,6 +12,7 @@ class Song():
|
|||
self.quit=exitFunc
|
||||
#self.prnt=prnt
|
||||
self.info = info
|
||||
self.info.tags = dict()
|
||||
# initialize player pipeline
|
||||
self.player = gst.Pipeline("player")
|
||||
bin = gst.element_factory_make("playbin",None)
|
||||
|
@ -48,7 +49,9 @@ class Song():
|
|||
#if self.quit != None:
|
||||
# self.quit("")
|
||||
elif t == gst.MESSAGE_TAG:
|
||||
self.info.tags = message.parse_tag()
|
||||
tags = message.parse_tag()
|
||||
for tag in tags.keys():
|
||||
self.info.tags[tag] = tags[tag]
|
||||
#self.taglist = message.parse_tag()
|
||||
return
|
||||
|
||||
|
@ -57,9 +60,8 @@ 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()
|
||||
while self.duration() == False:
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
# Change state to "paused"
|
||||
|
@ -73,10 +75,14 @@ class Song():
|
|||
|
||||
# Find the duration of the pipeline
|
||||
def duration(self):
|
||||
self.info.length = Duration()
|
||||
length = self.player.query_duration(self.time_format,None)[0]
|
||||
self.total = length
|
||||
self.info.length.setTime(length)
|
||||
try:
|
||||
self.info.length = Duration()
|
||||
length = self.player.query_duration(self.time_format,None)[0]
|
||||
self.total = length
|
||||
self.info.length.setTime(length)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
#self.length.disp(self.prnt)
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from duration import Duration
|
|||
class SongInfo:
|
||||
def __init__(self):
|
||||
self.filename = ""
|
||||
self.tags = None
|
||||
self.tags = dict()
|
||||
self.playCount = 0
|
||||
self.banned = False
|
||||
self.length = None
|
||||
|
|
Loading…
Reference in New Issue