Add skip functions to lockscreen

This commit is contained in:
tzugen 2021-05-06 12:53:43 +02:00
parent 85e2e473e5
commit a910818b70
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
1 changed files with 23 additions and 4 deletions

View File

@ -502,10 +502,9 @@ class MediaPlayerService : Service() {
val state: Int
val isPlaying = (playerState === PlayerState.STARTED)
var actions: Long = PlaybackStateCompat.ACTION_PLAY_PAUSE
// or
// PlaybackStateCompat.ACTION_SKIP_TO_NEXT or
// PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
var actions: Long = PlaybackStateCompat.ACTION_PLAY_PAUSE or
PlaybackStateCompat.ACTION_SKIP_TO_NEXT or
PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
// Map our playerState to native PlaybackState
// TODO: Synchronize these APIs
@ -829,6 +828,26 @@ class MediaPlayerService : Service() {
Timber.v("Media Session Callback: onStop")
}
override fun onSkipToNext() {
super.onSkipToNext()
getPendingIntentForMediaAction(
applicationContext,
KeyEvent.KEYCODE_MEDIA_NEXT,
keycode
).send()
Timber.v("Media Session Callback: onSkipToNext")
}
override fun onSkipToPrevious() {
super.onSkipToPrevious()
getPendingIntentForMediaAction(
applicationContext,
KeyEvent.KEYCODE_MEDIA_PREVIOUS,
keycode
).send()
Timber.v("Media Session Callback: onSkipToPrevious")
}
override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean {
// This probably won't be necessary once we implement more
// of the modern media APIs, like the MediaController etc.