[gnome-music/wip/mschraal/player-gapless-prev-next: 111/111] player: Fix previous/next on gapless playback




commit f0e080a53f619b624ed05afadf64d4a92b5580db
Author: Marinus Schraal <mschraal gnome org>
Date:   Thu Mar 26 08:57:57 2020 +0100

    player: Fix previous/next on gapless playback
    
    When the about-to-finish signal is received in Player, GstPlayer is
    prepared to play the next song in gapless mode. The previous() and
    next() calls in Player did not take into account this special case,
    resulting in an unresponsive Player.
    
    To fix this issue, next() now seeks to the start of the new stream.
    previous() does a start/stop cycle with the current song, as the new uri
    is already set and cannot be reverted.
    
    Closes: #375

 gnomemusic/player.py | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 0462eb48..c0497a6e 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -509,7 +509,9 @@ class Player(GObject.GObject):
 
         Play the next song of the playlist, if any.
         """
-        if self._playlist.next():
+        if self._gapless_set:
+            self.set_position(0.0)
+        elif self._playlist.next():
             self.play(self._playlist.props.current_song)
 
     def previous(self):
@@ -518,12 +520,24 @@ class Player(GObject.GObject):
         Play the previous song of the playlist, if any.
         """
         position = self._gst_player.props.position
-        if position >= 5:
-            self.set_position(0.0)
-            return
+        if self._gapless_set:
+            self.stop()
 
-        if self._playlist.previous():
+        if (position < 5
+                and self._playlist.has_previous()):
+            self._playlist.previous()
+            self._gapless_set = False
+            self.play(self._playlist.props.current_song)
+        # This is a special case for a song that is very short and the
+        # first song in the playlist. It can trigger gapless, but
+        # has_previous will return False.
+        elif (position < 5
+                and self._playlist.props.position == 0):
+            self.set_position(0.0)
+            self._gapless_set = False
             self.play(self._playlist.props.current_song)
+        else:
+            self.set_position(0.0)
 
     def play_pause(self):
         """Toggle play/pause state"""


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]