[gnome-music/wip/mschraal/artrework: 14/15] player: Fix MPRIS2 coverart update



commit 942864d75be7190856a78379dccc0674b88a16a8
Author: Marinus Schraal <mschraal gnome org>
Date:   Mon Jan 29 09:59:43 2018 +0100

    player: Fix MPRIS2 coverart update
    
    Pass a signal between Art, CoverArt, Player and MediaPlayer2Service that
    coverart is ready.

 gnomemusic/albumartcache.py      | 13 +++++++++++++
 gnomemusic/player.py             |  4 ++--
 gnomemusic/widgets/coverstack.py |  6 ++++++
 3 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/albumartcache.py b/gnomemusic/albumartcache.py
index 8286ae4..9c98bf7 100644
--- a/gnomemusic/albumartcache.py
+++ b/gnomemusic/albumartcache.py
@@ -227,6 +227,7 @@ class Art(GObject.GObject):
     def _cache_hit(self, klass, pixbuf):
         surface = _make_icon_frame(pixbuf, self._size, self._scale)
         self._surface = surface
+        self._set_grilo_thumbnail_path()
 
         self.emit('finished')
 
@@ -286,6 +287,18 @@ class Art(GObject.GObject):
 
         return False
 
+    def _set_grilo_thumbnail_path(self):
+        # TODO: This sets the thumbnail path for the Grilo Media object
+        # to be used by MPRIS. However, calling this by default for
+        # every cache hit is unnecessary.
+        album = utils.get_album_title(self._media)
+        artist = utils.get_artist_name(self._media)
+
+        success, thumb_file = MediaArt.get_file(artist, album, "album")
+        if success:
+            self._media.set_thumbnail(
+                GLib.filename_to_uri(thumb_file.get_path(), None))
+
     @GObject.Property
     @log
     def surface(self):
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 75e62e1..5432377 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -633,8 +633,7 @@ class Player(GObject.GObject):
         return False
 
     @log
-    def _on_cache_lookup(self, surface, data=None):
-        # FIXME: Need this for mpris
+    def _on_cover_stack_updated(self, klass):
         self.emit('thumbnail-updated')
 
     @log
@@ -778,6 +777,7 @@ class Player(GObject.GObject):
 
         stack = self._ui.get_object('cover')
         self._cover_stack = CoverStack(stack, Art.Size.XSMALL)
+        self._cover_stack.connect('updated', self._on_cover_stack_updated)
 
         self.duration = self._ui.get_object('duration')
         self.repeatBtnImage = self._ui.get_object('playlistRepeat')
diff --git a/gnomemusic/widgets/coverstack.py b/gnomemusic/widgets/coverstack.py
index c5f623f..fda824f 100644
--- a/gnomemusic/widgets/coverstack.py
+++ b/gnomemusic/widgets/coverstack.py
@@ -36,6 +36,10 @@ class CoverStack(GObject.GObject):
     or in between songs.
     """
 
+    __gsignals__ = {
+        'updated': (GObject.SignalFlags.RUN_FIRST, None, ())
+    }
+
     _default_icon = DefaultIcon()
 
     @log
@@ -85,3 +89,5 @@ class CoverStack(GObject.GObject):
         else:
             self._cover_b.set_from_surface(klass.surface)
             self._stack.set_visible_child_name("B")
+
+        self.emit('updated')


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