[gnome-music/wip/mschraal/gapless-v3: 12/18] Introduce gapless playback
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/gapless-v3: 12/18] Introduce gapless playback
- Date: Wed, 17 Oct 2018 22:54:26 +0000 (UTC)
commit 6d809ced431ac21d6b9e204cd574f4e4105ec0b7
Author: Marinus Schraal <mschraal gnome org>
Date: Wed Aug 22 01:39:11 2018 +0200
Introduce gapless playback
gnomemusic/gstplayer.py | 33 ++++++++++++++++++++++++++++-----
gnomemusic/player.py | 20 ++++++++++++++++----
gnomemusic/widgets/playertoolbar.py | 6 ++++--
gnomemusic/widgets/smoothscale.py | 3 +++
4 files changed, 51 insertions(+), 11 deletions(-)
---
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index b4648163..d909cf06 100644
--- a/gnomemusic/gstplayer.py
+++ b/gnomemusic/gstplayer.py
@@ -30,7 +30,7 @@ import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstAudio', '1.0')
gi.require_version('GstPbutils', '1.0')
-from gi.repository import Gtk, Gio, GObject, Gst, GstAudio, GstPbutils
+from gi.repository import Gtk, Gio, GLib, GObject, Gst, GstAudio, GstPbutils
from gnomemusic import log
from gnomemusic.playlists import Playlists
@@ -53,8 +53,9 @@ class GstPlayer(GObject.GObject):
Handles GStreamer interaction for Player and SmoothScale.
"""
__gsignals__ = {
- 'eos': (GObject.SignalFlags.RUN_FIRST, None, ()),
- 'clock-tick': (GObject.SignalFlags.RUN_FIRST, None, (int, ))
+ 'clock-tick': (GObject.SignalFlags.RUN_FIRST, None, (int, )),
+ 'eos': (GObject.SignalFlags.RUN_FIRST, None, (bool, )),
+ 'stream-start': (GObject.SignalFlags.RUN_FIRST, None, ())
}
def __repr__(self):
@@ -88,6 +89,9 @@ class GstPlayer(GObject.GObject):
self._bus.connect(
'message::duration-changed', self._on_duration_changed)
self._bus.connect('message::new-clock', self._on_new_clock)
+ self._bus.connect('message::stream-start', self._on_stream_start)
+
+ self._player.connect('about-to-finish', self._on_about_to_finish)
self._previous_state = Playback.STOPPED
self.props.state = Playback.STOPPED
@@ -117,6 +121,11 @@ class GstPlayer(GObject.GObject):
logger.debug("Replay Gain is not available")
return
+ @log
+ def _on_about_to_finish(self, klass, data=None):
+ print("about to finish")
+ self.emit('eos', True)
+
@log
def _on_replaygain_setting_changed(self, settings, value):
if value:
@@ -186,12 +195,25 @@ class GstPlayer(GObject.GObject):
message.src.get_name(), error.message))
logger.warning("Debugging info:\n{}".format(debug))
- self.emit('eos')
+ self.emit('eos', False)
return True
@log
def _on_bus_eos(self, bus, message):
- self.emit('eos')
+ print("bus eos")
+ self.emit('eos', False)
+
+ @log
+ def _on_stream_start(self, bus, message):
+ print("stream start")
+
+ def delayed_query(bus, message):
+ self._on_duration_changed(None, None)
+ self.emit('stream-start')
+
+ return False
+
+ GLib.timeout_add(1, delayed_query, bus, message)
@log
def _get_playback_status(self):
@@ -311,6 +333,7 @@ class GstPlayer(GObject.GObject):
:param float seconds: Position in seconds to seek
"""
+ print("seek", seconds)
# FIXME: seek should be signalled to MPRIS
self._player.seek_simple(
Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT,
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index f2dffcfc..e60c5a15 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -532,6 +532,8 @@ class Player(GObject.GObject):
self._player = GstPlayer()
self._player.connect('clock-tick', self._on_clock_tick)
self._player.connect('eos', self._on_eos)
+ self._player.connect('stream-start', self._on_stream_start)
+
self._player.bind_property(
'duration', self, 'duration', GObject.BindingFlags.SYNC_CREATE)
self._player.bind_property(
@@ -581,18 +583,28 @@ class Player(GObject.GObject):
if url_ != self._player.url:
self._player.url = url_
- self.emit('song-changed', self._playlist.get_current_index())
+ # self.emit('song-changed', self._playlist.get_current_index())
@log
- def _on_eos(self, klass):
+ def _on_eos(self, klass, gapless=False):
+ print("eos, gapless:", gapless)
def on_glib_idle():
self._playlist.next()
self.play()
if self.props.has_next:
- GLib.idle_add(on_glib_idle)
+ if gapless:
+ self._playlist.next()
+ new_url = self._playlist.props.current_song.get_url()
+ self._player.props.url = new_url
+ else:
+ GLib.idle_add(on_glib_idle)
else:
- self.stop()
+ GLib.idle_add(self.stop)
+
+ @log
+ def _on_stream_start(self, klass):
+ self.emit('song-changed', self._playlist.get_current_index())
@log
def play(self, song_index=None):
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index 7c0b69ca..3bafbf23 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -156,8 +156,10 @@ class PlayerToolbar(Gtk.ActionBar):
:param int position: current song position
"""
current_song = player.props.current_song
- self._duration_label.set_label(
- utils.seconds_to_string(current_song.get_duration()))
+ duration = player.props.duration
+ if duration != -1:
+ self._duration_label.set_label(
+ utils.seconds_to_string(int(duration)))
self._play_button.set_sensitive(True)
self._sync_prev_next()
diff --git a/gnomemusic/widgets/smoothscale.py b/gnomemusic/widgets/smoothscale.py
index aa607525..9a13733a 100644
--- a/gnomemusic/widgets/smoothscale.py
+++ b/gnomemusic/widgets/smoothscale.py
@@ -110,10 +110,13 @@ class SmoothScale(Gtk.Scale):
@log
def _on_duration_changed(self, klass, arguments):
duration = self._player.duration
+ print("duration changed", duration)
if duration != -1.:
self.set_range(0.0, duration * 60)
self.set_increments(300, 600)
+ self.set_value(0)
+ self._on_smooth_scale_event(None, None)
@log
def _on_smooth_scale_seek_finish(self, value):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]