[Android] Update player when nowplaying is changed
Geoffrey Métais
git at videolan.org
Tue Jan 26 15:36:24 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jan 26 14:32:36 2016 +0100| [5a81f1d21ff612c07abfc47c6754967777f4d9a9] | committer: Geoffrey Métais
Update player when nowplaying is changed
> https://code.videolan.org/videolan/vlc-android/commit/5a81f1d21ff612c07abfc47c6754967777f4d9a9
---
.../src/org/videolan/vlc/PlaybackService.java | 29 +++++++++++++++-------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 9d36920..ee5af88 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -538,15 +538,13 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
switch (event.type) {
case Media.Event.MetaChanged:
/* Update Meta if file is already parsed */
- if (!mParsed)
- break;
+ if (mParsed && updateCurrentMeta(event.getMetaId()))
+ executeUpdate();
Log.i(TAG, "Media.Event.MetaChanged: " + event.getMetaId());
-
+ break;
case Media.Event.ParsedChanged:
Log.i(TAG, "Media.Event.ParsedChanged");
- final MediaWrapper mw = getCurrentMedia();
- if (mw != null)
- mw.updateMeta(mMediaPlayer);
+ updateCurrentMeta(-1);
mParsed = true;
break;
@@ -556,6 +554,21 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
}
};
+ /**
+ * Update current media meta and return true if player needs to be updated
+ *
+ * @param id of the Meta event received, -1 for none
+ * @return true if UI needs to be updated
+ */
+ private boolean updateCurrentMeta(int id) {
+ if (id == Media.Meta.Publisher)
+ return false;
+ final MediaWrapper mw = getCurrentMedia();
+ if (mw != null)
+ mw.updateMeta(mMediaPlayer);
+ return id != Media.Meta.NowPlaying || getCurrentMedia().getNowPlaying() != null;
+ }
+
private final MediaPlayer.EventListener mMediaPlayerListener = new MediaPlayer.EventListener() {
@Override
@@ -599,7 +612,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
executeUpdate();
publishState(event.type);
executeUpdateProgress();
- showNotification();
if (mWakeLock.isHeld())
mWakeLock.release();
break;
@@ -644,7 +656,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
if (!handleVout()) {
/* Update notification content intent: resume video or resume audio activity */
updateMetadata();
- showNotification();
}
}
break;
@@ -759,7 +770,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
if (updateWidget)
updateWidget();
updateMetadata();
-
}
private void executeUpdateProgress() {
@@ -1106,6 +1116,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
i.putExtra("track", media.getTitle());
sendBroadcast(i);
}
+ showNotification();
}
protected void publishState(int state) {
More information about the Android
mailing list