[Android] Set mediasession paused instead of stopped on TV
Geoffrey Métais
git at videolan.org
Thu Nov 23 11:13:02 CET 2017
vlc-android | branch: 2.5.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Nov 22 17:29:05 2017 +0100| [ceb237db8d39b4c1b14e1e3378bbc763227d89eb] | committer: Geoffrey Métais
Set mediasession paused instead of stopped on TV
This allows to have a 'Now Playing' card to easily resume playback
(cherry picked from commit 47092e2f1e3c031927dc3e3844533e5d8e378b19)
> https://code.videolan.org/videolan/vlc-android/commit/ceb237db8d39b4c1b14e1e3378bbc763227d89eb
---
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 e6d94dc4b..3846aa7f0 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -1451,16 +1451,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())
@@ -1474,7 +1477,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