[gnome-music/wip/mschraal/player-no-play-empty-playlist: 1/2] player: Do not set playing on an emtpy playlist



commit bd4c13ef90180ab57374f87dc2c0019bfd8c5077
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri Jan 3 10:51:35 2020 +0100

    player: Do not set playing on an emtpy playlist
    
    If the playlist model is empty, do not allow to set a song. This will
    result in a crash.
    
    In Player the 'play' function has to add an extra check if there is a
    current song to play before setting state.
    
    Fixes: #354, #355

 gnomemusic/player.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 0e23754a..9c645db3 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -235,6 +235,9 @@ class PlayerPlaylist(GObject.GObject):
         :returns: The selected song
         :rtype: CoreSong
         """
+        if self._model.get_n_items() == 0:
+            return None
+
         if song is None:
             if self.props.repeat_mode == RepeatMode.SHUFFLE:
                 position = randrange(0, self._model.get_n_items())
@@ -505,7 +508,8 @@ class Player(GObject.GObject):
         if coresong is not None:
             self._load(coresong)
 
-        self._gst_player.props.state = Playback.PLAYING
+        if self.props.current_song is not None:
+            self._gst_player.props.state = Playback.PLAYING
 
     @log
     def pause(self):


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