[Android] Do not constantly publish mediasession progress

Geoffrey Métais git at videolan.org
Fri May 4 11:28:11 CEST 2018


vlc-android | branch: 3.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri May  4 09:54:38 2018 +0200| [b302c6fb8362d43c54c3069178f1b31f719fcb62] | committer: Geoffrey Métais

Do not constantly publish mediasession progress

This was spamming the whole framework for unnecessary updates.
Especially Android Auto via Bluetooth.

Auto and Now Playing card fake this progress, it was not needed at all.

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

 vlc-android/src/org/videolan/vlc/PlaybackService.java | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 864afb210..e2cdd34ba 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -113,7 +113,7 @@ public class PlaybackService extends MediaBrowserServiceCompat{
     private static final int SHOW_PROGRESS = 0;
     private static final int SHOW_TOAST = 1;
     private static final int END_MEDIASESSION = 2;
-    private static final int PUBLISH_STATE = 3;
+    private static final int PUBLISH_PROGRESS = 3;
 
     private static final long DELAY_DOUBLE_CLICK = 800L;
     private static final long DELAY_LONG_CLICK = 1000L;
@@ -547,8 +547,7 @@ public class PlaybackService extends MediaBrowserServiceCompat{
                 case MediaPlayer.Event.TimeChanged:
                     break;
                 case MediaPlayer.Event.PositionChanged:
-                    updateWidgetPosition(event.getPositionChanged());
-                    mHandler.sendEmptyMessage(PUBLISH_STATE);
+                    if (mWidget != 0) mHandler.obtainMessage(PUBLISH_PROGRESS, event.getPositionChanged())
                     break;
                 case MediaPlayer.Event.Vout:
                     break;
@@ -642,10 +641,10 @@ public class PlaybackService extends MediaBrowserServiceCompat{
                 case END_MEDIASESSION:
                     if (service.mMediaSession != null) service.mMediaSession.setActive(false);
                     break;
-                case PUBLISH_STATE:
+                case PUBLISH_PROGRESS:
                     final long time = System.currentTimeMillis();
                     if (time - lastPublicationDate > 1000L) {
-                        service.publishState();
+                        service.updateWidgetPosition((Float) msg.obj);
                         lastPublicationDate = time;
                     }
                     break;



More information about the Android mailing list