[gnome-music/wip/mschraal/gapless-v3: 80/83] Introduce gapless playback
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/gapless-v3: 80/83] Introduce gapless playback
- Date: Mon, 15 Oct 2018 15:25:58 +0000 (UTC)
commit 7651edaab85fc4ae867364f480f32b62f56c1661
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 | 19 +++++++++++++++----
gnomemusic/widgets/playertoolbar.py | 6 ++++--
gnomemusic/widgets/smoothscale.py | 3 +++
4 files changed, 50 insertions(+), 11 deletions(-)
---
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index ec67891c..b9b6c332 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.state = Playback.STOPPED
@@ -116,6 +120,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:
@@ -183,12 +192,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):
@@ -308,6 +330,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 1da1f16b..99fc6f17 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -530,6 +530,7 @@ 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)
root_window = parent_window.get_toplevel()
self._inhibit_suspend = InhibitSuspend(root_window, self)
@@ -575,18 +576,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 5091dd13..cc4e8ff8 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -161,8 +161,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._player.props.duration
+ if duration is not None:
+ 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 e995540b..50c7356f 100644
--- a/gnomemusic/widgets/smoothscale.py
+++ b/gnomemusic/widgets/smoothscale.py
@@ -117,10 +117,13 @@ class SmoothScale(Gtk.Scale):
@log
def _on_duration_changed(self, klass, arguments):
duration = self._player.duration
+ print("duration changed", duration)
if duration is not None:
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]