From 42b4b48d849e69562b4e92ce520f309ff2289c00 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Thu, 4 Jun 2009 14:46:22 +0000 Subject: [PATCH] Keep trying to find duration until success git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@14 1daee41c-8060-4895-b1f0-2197c00d777a --- trunk/ocarina.py | 24 ++++++++++++------------ trunk/operations.py | 14 ++++++++++++++ trunk/song.py | 22 ++++++++++++++-------- trunk/songInfo.py | 2 +- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/trunk/ocarina.py b/trunk/ocarina.py index 70951d10..eb24320e 100644 --- a/trunk/ocarina.py +++ b/trunk/ocarina.py @@ -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): diff --git a/trunk/operations.py b/trunk/operations.py index 4d3e8793..d0638a3c 100644 --- a/trunk/operations.py +++ b/trunk/operations.py @@ -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 diff --git a/trunk/song.py b/trunk/song.py index 0f901b35..59610a09 100644 --- a/trunk/song.py +++ b/trunk/song.py @@ -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) diff --git a/trunk/songInfo.py b/trunk/songInfo.py index adecf433..88c19fff 100644 --- a/trunk/songInfo.py +++ b/trunk/songInfo.py @@ -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