[Android] Filter widget cover update from playback service

Geoffrey Métais git at videolan.org
Wed Aug 9 15:12:35 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Aug  9 15:11:59 2017 +0200| [e6c24b237532f387625584d8f43048584ae5e527] | committer: Geoffrey Métais

Filter widget cover update from playback service

> https://code.videolan.org/videolan/vlc-android/commit/e6c24b237532f387625584d8f43048584ae5e527
---

 .../src/org/videolan/vlc/PlaybackService.java      |  9 ++++-
 .../videolan/vlc/widget/VLCAppWidgetProvider.java  | 46 ++++++++++------------
 2 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 9c3cba5af..ce7a2d5ec 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -1515,9 +1515,14 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
         sendBroadcast(widgetIntent);
     }
 
+    private String mCurrentWidgetCover = null;
     private void updateWidgetCover() {
-        sendBroadcast(new Intent(VLCAppWidgetProvider.ACTION_WIDGET_UPDATE_COVER)
-                        .putExtra("artworkMrl", hasCurrentMedia() ? getCurrentMedia().getArtworkMrl() : null));
+    String newWidgetCover = hasCurrentMedia() ? getCurrentMedia().getArtworkMrl() : null;
+        if (!TextUtils.equals(mCurrentWidgetCover, newWidgetCover)) {
+            mCurrentWidgetCover = newWidgetCover;
+            sendBroadcast(new Intent(VLCAppWidgetProvider.ACTION_WIDGET_UPDATE_COVER)
+                            .putExtra("artworkMrl", newWidgetCover));
+        }
     }
 
     private void updateWidgetPosition(final float pos) {
diff --git a/vlc-android/src/org/videolan/vlc/widget/VLCAppWidgetProvider.java b/vlc-android/src/org/videolan/vlc/widget/VLCAppWidgetProvider.java
index 289096ce7..1d19548fc 100644
--- a/vlc-android/src/org/videolan/vlc/widget/VLCAppWidgetProvider.java
+++ b/vlc-android/src/org/videolan/vlc/widget/VLCAppWidgetProvider.java
@@ -57,7 +57,6 @@ abstract public class VLCAppWidgetProvider extends AppWidgetProvider {
     public static final String ACTION_WIDGET_UPDATE_POSITION = ACTION_WIDGET_PREFIX+"UPDATE_POSITION";
     public static final String ACTION_WIDGET_ENABLED = ACTION_WIDGET_PREFIX+"ENABLED";
     public static final String ACTION_WIDGET_DISABLED = ACTION_WIDGET_PREFIX+"DISABLED";
-    private static String sCurrentArtworkMrl;
 
     @Override
     public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
@@ -118,30 +117,27 @@ abstract public class VLCAppWidgetProvider extends AppWidgetProvider {
             views.setImageViewResource(R.id.play_pause, getPlayPauseImage(isplaying));
         } else if (ACTION_WIDGET_UPDATE_COVER.equals(action)) {
             final String artworkMrl = intent.getStringExtra("artworkMrl");
-            if (!TextUtils.equals(sCurrentArtworkMrl, artworkMrl)) {
-                sCurrentArtworkMrl = ""+artworkMrl;
-                if (!TextUtils.isEmpty(artworkMrl)) {
-                    VLCApplication.runBackground(new Runnable() {
-                        @Override
-                        public void run() {
-                            final Bitmap cover = AudioUtil.readCoverBitmap(Uri.decode(artworkMrl), 320);
-                            VLCApplication.runOnMainThread(new Runnable() {
-                                @Override
-                                public void run() {
-                                    if (cover != null)
-                                        views.setImageViewBitmap(R.id.cover, cover);
-                                    else
-                                        views.setImageViewResource(R.id.cover, R.drawable.icon);
-                                    views.setProgressBar(R.id.timeline, 100, 0, false);
-                                    applyUpdate(context, views, partial);
-                                }
-                            });
-                        }
-                    });
-                } else
-                    views.setImageViewResource(R.id.cover, R.drawable.icon);
-                views.setProgressBar(R.id.timeline, 100, 0, false);
-            }
+            if (!TextUtils.isEmpty(artworkMrl)) {
+                VLCApplication.runBackground(new Runnable() {
+                    @Override
+                    public void run() {
+                        final Bitmap cover = AudioUtil.readCoverBitmap(Uri.decode(artworkMrl), 320);
+                        VLCApplication.runOnMainThread(new Runnable() {
+                            @Override
+                            public void run() {
+                                if (cover != null)
+                                    views.setImageViewBitmap(R.id.cover, cover);
+                                else
+                                    views.setImageViewResource(R.id.cover, R.drawable.icon);
+                                views.setProgressBar(R.id.timeline, 100, 0, false);
+                                applyUpdate(context, views, partial);
+                            }
+                        });
+                    }
+                });
+            } else
+                views.setImageViewResource(R.id.cover, R.drawable.icon);
+            views.setProgressBar(R.id.timeline, 100, 0, false);
         } else if (ACTION_WIDGET_UPDATE_POSITION.equals(action)) {
             final float pos = intent.getFloatExtra("position", 0f);
             views.setProgressBar(R.id.timeline, 100, (int) (100 * pos), false);



More information about the Android mailing list