mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-07-30 07:34:46 +02:00
Refresh media session connector actions when changing speed on app. Update rounding values for Android Auto speed icons
This commit is contained in:
parent
b2b647e2f7
commit
86c5d1a3e9
2 changed files with 30 additions and 17 deletions
|
@ -33,7 +33,7 @@ class MediaManager(private var apiHandler: ApiHandler, var ctx: Context) {
|
|||
var serverItemsInProgress = listOf<ItemInProgress>()
|
||||
var serverLibraries = listOf<Library>()
|
||||
|
||||
private var userSettingsPlaybackRate:Float? = null
|
||||
var userSettingsPlaybackRate:Float? = null
|
||||
|
||||
fun getIsLibrary(id:String) : Boolean {
|
||||
return serverLibraries.find { it.id == id } != null
|
||||
|
|
|
@ -381,24 +381,15 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
}
|
||||
|
||||
isClosed = false
|
||||
val customActionProviders = mutableListOf(
|
||||
JumpBackwardCustomActionProvider(),
|
||||
JumpForwardCustomActionProvider(),
|
||||
ChangePlaybackSpeedCustomActionProvider() // Will be pushed to far left
|
||||
)
|
||||
|
||||
val metadata = playbackSession.getMediaMetadataCompat(ctx)
|
||||
mediaSession.setMetadata(metadata)
|
||||
val mediaItems = playbackSession.getMediaItems()
|
||||
val playbackRateToUse = playbackRate ?: initialPlaybackRate ?: 1f
|
||||
initialPlaybackRate = playbackRate
|
||||
|
||||
if (playbackSession.mediaPlayer != PLAYER_CAST && mediaItems.size > 1) {
|
||||
customActionProviders.addAll(listOf(
|
||||
SkipBackwardCustomActionProvider(),
|
||||
SkipForwardCustomActionProvider(),
|
||||
))
|
||||
}
|
||||
mediaSessionConnector.setCustomActionProviders(*customActionProviders.toTypedArray())
|
||||
// Set actions on Android Auto like jump forward/backward
|
||||
setMediaSessionConnectorCustomActions(playbackSession)
|
||||
|
||||
playbackSession.mediaPlayer = getMediaPlayer()
|
||||
|
||||
|
@ -476,6 +467,22 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun setMediaSessionConnectorCustomActions(playbackSession:PlaybackSession) {
|
||||
val mediaItems = playbackSession.getMediaItems()
|
||||
val customActionProviders = mutableListOf(
|
||||
JumpBackwardCustomActionProvider(),
|
||||
JumpForwardCustomActionProvider(),
|
||||
ChangePlaybackSpeedCustomActionProvider() // Will be pushed to far left
|
||||
)
|
||||
if (playbackSession.mediaPlayer != PLAYER_CAST && mediaItems.size > 1) {
|
||||
customActionProviders.addAll(listOf(
|
||||
SkipBackwardCustomActionProvider(),
|
||||
SkipForwardCustomActionProvider(),
|
||||
))
|
||||
}
|
||||
mediaSessionConnector.setCustomActionProviders(*customActionProviders.toTypedArray())
|
||||
}
|
||||
|
||||
fun handlePlayerPlaybackError(errorMessage:String) {
|
||||
// On error and was attempting to direct play - fallback to transcode
|
||||
currentPlaybackSession?.let { playbackSession ->
|
||||
|
@ -828,7 +835,13 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
}
|
||||
|
||||
fun setPlaybackSpeed(speed: Float) {
|
||||
mediaManager.userSettingsPlaybackRate = speed
|
||||
currentPlayer.setPlaybackSpeed(speed)
|
||||
|
||||
// Refresh Android Auto actions
|
||||
mediaProgressSyncer.currentPlaybackSession?.let {
|
||||
setMediaSessionConnectorCustomActions(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun closePlayback(calledOnError:Boolean? = false) {
|
||||
|
@ -1193,10 +1206,10 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
val drawable: Int = when (playbackRate) {
|
||||
in 0.5f..0.7f -> R.drawable.ic_play_speed_0_5x
|
||||
in 0.8f..1.0f -> R.drawable.ic_play_speed_1_0x
|
||||
in 1.1f..1.2f -> R.drawable.ic_play_speed_1_2x
|
||||
in 1.3f..1.5f -> R.drawable.ic_play_speed_1_5x
|
||||
in 1.6f..2.0f -> R.drawable.ic_play_speed_2_0x
|
||||
in 2.1f..3.0f -> R.drawable.ic_play_speed_3_0x
|
||||
in 1.1f..1.3f -> R.drawable.ic_play_speed_1_2x
|
||||
in 1.4f..1.7f -> R.drawable.ic_play_speed_1_5x
|
||||
in 1.8f..2.4f -> R.drawable.ic_play_speed_2_0x
|
||||
in 2.5f..3.0f -> R.drawable.ic_play_speed_3_0x
|
||||
// anything set above 3 will be show the 3x to save from creating 100 icons
|
||||
else -> R.drawable.ic_play_speed_3_0x
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue