Issue #2105 : support optional rewind in lockscreen (by using skipToPrevious button)

This commit is contained in:
orionlee 2016-09-09 09:00:36 -07:00
parent 4a1e728ac5
commit 01c3f757a1
1 changed files with 23 additions and 2 deletions

View File

@ -996,13 +996,34 @@ public class PlaybackService extends MediaBrowserServiceCompat {
state = PlaybackStateCompat.STATE_NONE;
}
sessionState.setState(state, mediaPlayer.getPosition(), mediaPlayer.getPlaybackSpeed());
sessionState.setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE
long capabilities = PlaybackStateCompat.ACTION_PLAY_PAUSE
| PlaybackStateCompat.ACTION_REWIND
| PlaybackStateCompat.ACTION_FAST_FORWARD
| PlaybackStateCompat.ACTION_SKIP_TO_NEXT);
| PlaybackStateCompat.ACTION_SKIP_TO_NEXT;
if (useSkipToPreviousForRewindInLockscreen()) {
// Workaround to fool Android so that Lockscreen will expose a skip-to-previous button,
// which will be used for rewind.
//
// @see #sessionCallback in the backing callback, skipToPrevious implementation
// is actually the same as rewind. So no new inconsistency is created.
capabilities = capabilities | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;
}
sessionState.setActions(capabilities);
mediaSession.setPlaybackState(sessionState.build());
}
private static boolean useSkipToPreviousForRewindInLockscreen() {
// showRewindOnCompactNotification() corresponds to the "Set Lockscreen Buttons"
// Settings in UI.
// Hence, from user perspective, he/she is setting the buttons for Loackscreen
//
// OPEN: it might contain other logic, e.g., the woakround might be applicable
// only to prev-Androidv5 devices.
return UserPreferences.showRewindOnCompactNotification();
}
/**
* Used by updateMediaSessionMetadata to load notification data in another thread.
*/