diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2016-10-02 22:35:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-02 22:35:00 +0200 |
commit | 44eb1a9cfd6d43f45ad3dedc7079998133a2ea3a (patch) | |
tree | 8b3c9b9be54cafb7ed6187943f3e50afda3f1861 /core/src/main/java/de | |
parent | 6fd909689dbcb6f8d73b8e048061191f052959cb (diff) | |
parent | 209058b3a7be15d8b3837ace29822eeb6d52960d (diff) | |
download | AntennaPod-44eb1a9cfd6d43f45ad3dedc7079998133a2ea3a.zip |
Merge pull request #2117 from orionlee/2105_support_rewind_in_lockscreen
Issue #2105 : support optional rewind in lockscreen
Diffstat (limited to 'core/src/main/java/de')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 04b5b676d..eca3d1bb9 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -996,13 +996,37 @@ 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. + // The workaround is used for pre Lollipop (Androidv5) devices. + // For Androidv5+, lockscreen widges are really notifications (compact), + // with an independent codepath + // + // @see #sessionCallback in the backing callback, skipToPrevious implementation + // is actually the same as rewind. So no new inconsistency is created. + // @see #setupNotification() for the method to create Androidv5+ lockscreen UI + // with notification (compact) + 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 Lockscreen + return ( UserPreferences.showRewindOnCompactNotification() && + (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) ); + } + /** * Used by updateMediaSessionMetadata to load notification data in another thread. */ |