Show custom actions in music widget
This commit is contained in:
@@ -8,6 +8,7 @@ import android.content.pm.PackageManager
|
||||
import android.graphics.Bitmap
|
||||
import android.media.AudioManager
|
||||
import android.media.MediaMetadata
|
||||
import android.media.Rating
|
||||
import android.media.session.MediaController
|
||||
import android.media.session.MediaSession
|
||||
import android.media.session.PlaybackState.CustomAction
|
||||
@@ -67,6 +68,7 @@ interface MusicService {
|
||||
fun play()
|
||||
fun togglePause()
|
||||
fun seekTo(position: Long)
|
||||
fun performCustomAction(action: CustomAction)
|
||||
fun openPlayer(): PendingIntent?
|
||||
|
||||
fun openPlayerChooser(context: Context)
|
||||
@@ -552,6 +554,13 @@ internal class MusicServiceImpl(
|
||||
)
|
||||
}
|
||||
|
||||
override fun performCustomAction(action: CustomAction) {
|
||||
scope.launch {
|
||||
val controller = currentMediaController.firstOrNull()
|
||||
controller?.transportControls?.sendCustomAction(action.action, action.extras)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMusicApps(): Set<String> {
|
||||
// List of known music apps that don't have the correct intent filter
|
||||
val apps = mutableSetOf(
|
||||
|
||||
@@ -2,6 +2,8 @@ package de.mm20.launcher2.music
|
||||
|
||||
import android.media.session.PlaybackState
|
||||
import android.media.session.PlaybackState.CustomAction
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
|
||||
data class SupportedActions(
|
||||
val stop: Boolean = false,
|
||||
@@ -24,5 +26,14 @@ data class SupportedActions(
|
||||
setPlaybackSpeed = actions?.and(PlaybackState.ACTION_SET_PLAYBACK_SPEED) == PlaybackState.ACTION_SET_PLAYBACK_SPEED,
|
||||
setRating = actions?.and(PlaybackState.ACTION_SET_RATING) == PlaybackState.ACTION_SET_RATING,
|
||||
customActions = customActions ?: emptyList(),
|
||||
)
|
||||
) {
|
||||
for (action in customActions ?: emptyList()) {
|
||||
Log.d("MM20", action.action.toString())
|
||||
val extras = action.extras ?: Bundle.EMPTY
|
||||
val keySet = extras.keySet()
|
||||
for (key in keySet) {
|
||||
Log.d("MM20", "$key: ${extras.get(key)}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user