[gnome-music/wip/jfelder/core-restore-player-validation: 6/6] player: Try to load the next song if the current one is unplayable



commit 4fa46ae69ea73bbc4dadca0c80788644b756df4d
Author: Jean Felder <jfelder src gnome org>
Date:   Sun Jul 14 19:28:14 2019 +0200

    player: Try to load the next song if the current one is unplayable
    
    There are 3 different cases to consider to handle an unplayable song.
    
    1. If the song comes from the call of the previous or next method.
    This case is already handled by the previous commit. Indeed, at the
    beginning of a song, two validations occur: the current song and the
    next (or previous). So, it's possible to check if the next song is
    valid at the beginning of each song.
    
    2. If the user tries to load a song whose state is unknown.
    In that case, GstPlayer will emit an error signal which is received by
    the Player. This song will be set as unplayable and the player will
    try to load the next one.
    
    2. If the user tries to load a song whose state is known as invalid.
    In that case, the player will automatically try to play the next
    song.
    
    Note: The RepeatMode song is not handled because the next method will
    always return the same song.

 gnomemusic/gstplayer.py |  3 ++-
 gnomemusic/player.py    | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index 12d300b7..0c4591f6 100644
--- a/gnomemusic/gstplayer.py
+++ b/gnomemusic/gstplayer.py
@@ -54,6 +54,7 @@ class GstPlayer(GObject.GObject):
         "about-to-finish": (GObject.SignalFlags.RUN_FIRST, None, ()),
         "clock-tick": (GObject.SignalFlags.RUN_FIRST, None, (int, )),
         'eos': (GObject.SignalFlags.RUN_FIRST, None, ()),
+        "error": (GObject.SignalFlags.RUN_FIRST, None, ()),
         'seek-finished': (GObject.SignalFlags.RUN_FIRST, None, ()),
         "stream-start": (GObject.SignalFlags.RUN_FIRST, None, ())
     }
@@ -196,7 +197,7 @@ class GstPlayer(GObject.GObject):
                 message.src.get_name(), error.message))
         logger.warning("Debugging info:\n{}".format(debug))
 
-        self.emit('eos')
+        self.emit("error")
         return True
 
     @log
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 6a64bc42..2f7943d7 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -425,6 +425,7 @@ class Player(GObject.GObject):
         self._gst_player.connect("about-to-finish", self._on_about_to_finish)
         self._gst_player.connect('clock-tick', self._on_clock_tick)
         self._gst_player.connect('eos', self._on_eos)
+        self._gst_player.connect("error", self._on_error)
         self._gst_player.connect('seek-finished', self._on_seek_finished)
         self._gst_player.connect("stream-start", self._on_stream_start)
         self._gst_player.bind_property(
@@ -485,6 +486,16 @@ class Player(GObject.GObject):
 
         self._gapless_set = False
 
+    def _on_error(self, klass=None):
+        self.stop()
+        self._gapless_set = False
+
+        current_song = self.props.current_song
+        current_song.props.validation = CoreSong.Validation.FAILED
+        if (self.has_next
+                and self.props.repeat_mode != RepeatMode.SONG):
+            self.next()
+
     def _on_stream_start(self, klass):
         self._gapless_set = False
         self._time_stamp = int(time.time())
@@ -508,6 +519,12 @@ class Player(GObject.GObject):
         if self.props.current_song is None:
             coresong = self._playlist.set_song(coresong)
 
+        if (coresong is not None
+                and coresong.props.validation == CoreSong.Validation.FAILED
+                and self.props.repeat_mode != RepeatMode.SONG):
+            self._on_error()
+            return
+
         if coresong is not None:
             self._load(coresong)
 


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