bpd: Added correct error check for query_position/query_duration

This commit is contained in:
Philipp Beckmann 2016-06-20 18:09:37 +02:00
parent 0917e675d7
commit 5613d9d4ea
2 changed files with 15 additions and 4 deletions

View file

@ -1167,7 +1167,7 @@ class BPDPlugin(BeetsPlugin):
server.run()
except NoGstreamerError:
global_log.error(u'Gstreamer Python bindings not found.')
global_log.error(u'Install "python-gst0.10", "py27-gst-python", '
global_log.error(u'Install "python-gst-1.0" '
u'or similar package to use BPD.')
def commands(self):

View file

@ -33,6 +33,9 @@ from gi.repository import GObject, Gst
GObject.threads_init()
Gst.init(None)
class QueryError(Exception):
pass
class GstPlayer(object):
"""A music player abstracting GStreamer's Playbin element.
@ -165,12 +168,20 @@ class GstPlayer(object):
"""
fmt = Gst.Format(Gst.Format.TIME)
try:
pos = self.player.query_position(fmt)[1] / (10 ** 9)
length = self.player.query_duration(fmt)[1] / (10 ** 9)
posq = self.player.query_position(fmt)
if not posq[0]:
raise QueryError("query_position failed")
pos = posq[1] / (10 ** 9)
lengthq = self.player.query_duration(fmt)
if not lengthq[0]:
raise QueryError("query_duration failed")
length = lengthq[1] / (10 ** 9)
self.cached_time = (pos, length)
return (pos, length)
except Exception:
except QueryError:
# Stream not ready. For small gaps of time, for instance
# after seeking, the time values are unavailable. For this
# reason, we cache recent.