[Android] Set mediasession paused instead of stopped on TV
Geoffrey Métais
git at videolan.org
Wed Nov 22 18:01:25 CET 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Nov 22 17:29:05 2017 +0100| [40d5edf3e529028ebd836f6cc95503aa5ce2dde4] | committer: Geoffrey Métais
Set mediasession paused instead of stopped on TV
This allows to have a 'Now Playing' card to easily resume playback
> https://code.videolan.org/videolan/vlc-android/commit/40d5edf3e529028ebd836f6cc95503aa5ce2dde4
---
vlc-android/src/org/videolan/vlc/PlaybackService.java | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 3722a444d..c3cd00c5e 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -1450,16 +1450,19 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
return;
final PlaybackStateCompat.Builder pscb = new PlaybackStateCompat.Builder();
long actions = PLAYBACK_BASE_ACTIONS;
+ final boolean hasMedia = hasCurrentMedia();
+ int state;
if (!mStopped && isPlaying()) {
actions |= PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_STOP;
- pscb.setState(PlaybackStateCompat.STATE_PLAYING, getTime(), getRate());
- } else if (!mStopped && hasMedia()) {
+ state = PlaybackStateCompat.STATE_PLAYING;
+ } else if (!mStopped && hasMedia) {
actions |= PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_STOP;
- pscb.setState(PlaybackStateCompat.STATE_PAUSED, getTime(), getRate());
+ state = PlaybackStateCompat.STATE_PAUSED;
} else {
actions |= PlaybackStateCompat.ACTION_PLAY;
- pscb.setState(PlaybackStateCompat.STATE_STOPPED, getTime(), getRate());
+ state = AndroidDevices.isAndroidTv && hasMedia ? PlaybackStateCompat.STATE_PAUSED : PlaybackStateCompat.STATE_STOPPED;
}
+ pscb.setState(state, getTime(), getRate());
if (mRepeating != REPEAT_NONE || hasNext())
actions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT;
if (mRepeating != REPEAT_NONE || hasPrevious() || isSeekable())
@@ -1473,7 +1476,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
pscb.addCustomAction("shuffle", getString(R.string.shuffle_title), isShuffling() ? R.drawable.ic_auto_shuffle_pressed : R.drawable.ic_auto_shuffle_normal);
pscb.addCustomAction("repeat", getString(R.string.repeat_title), repeatResId);
mMediaSession.setPlaybackState(pscb.build());
- mMediaSession.setActive(hasMedia());
+ mMediaSession.setActive(state != PlaybackStateCompat.STATE_STOPPED);
mMediaSession.setQueueTitle(getString(R.string.music_now_playing));
}
More information about the Android
mailing list