[Android] Set mediasession paused instead of stopped on TV
Geoffrey Métais
git at videolan.org
Wed Nov 22 18:17:07 CET 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Nov 22 17:29:05 2017 +0100| [47092e2f1e3c031927dc3e3844533e5d8e378b19] | 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/47092e2f1e3c031927dc3e3844533e5d8e378b19
---
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 d38ddbed4..8572df18b 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -1449,16 +1449,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())
@@ -1472,7 +1475,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