From bf6e97e5b9a45b023f24e0b6e04673cd71ddaebe Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 14 Dec 2015 22:22:56 +0100 Subject: [PATCH] gst1: Fix querying of duration of MP3s --- mopidy/audio/scan.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mopidy/audio/scan.py b/mopidy/audio/scan.py index fb0773d6..188eb26c 100644 --- a/mopidy/audio/scan.py +++ b/mopidy/audio/scan.py @@ -115,13 +115,23 @@ def _start_pipeline(pipeline): pipeline.set_state(Gst.State.PLAYING) -def _query_duration(pipeline): +def _query_duration(pipeline, timeout=100): success, duration = pipeline.query_duration(Gst.Format.TIME) + if success and duration >= 0: + return duration // Gst.MSECOND - if not success or duration < 0: + result = pipeline.set_state(Gst.State.PLAYING) + if result == Gst.StateChangeReturn.FAILURE: return None - return duration // Gst.MSECOND + gst_timeout = timeout * Gst.MSECOND + bus = pipeline.get_bus() + bus.timed_pop_filtered(gst_timeout, Gst.MessageType.DURATION_CHANGED) + + success, duration = pipeline.query_duration(Gst.Format.TIME) + if success and duration >= 0: + return duration // Gst.MSECOND + return None def _query_seekable(pipeline):