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



commit 75ea51c0ad7dff0a26093e696b8804abf14bd671
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]