diff --git a/android/app/src/main/java/com/audiobookshelf/app/MainActivity.kt b/android/app/src/main/java/com/audiobookshelf/app/MainActivity.kt index 339954ee..99ce3a8d 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/MainActivity.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/MainActivity.kt @@ -103,6 +103,9 @@ class MainActivity : BridgeActivity() { } } + fun isPlayerNotificationServiceInitialized():Boolean { + return ::foregroundService.isInitialized + } fun stopMyService() { if (mBounded) { diff --git a/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt b/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt index 0a82b93b..240be8d3 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt @@ -329,18 +329,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { } } - var playbackActions = PlaybackStateCompat.ACTION_PLAY_PAUSE or - PlaybackStateCompat.ACTION_PLAY or - PlaybackStateCompat.ACTION_PAUSE or - PlaybackStateCompat.ACTION_FAST_FORWARD or - PlaybackStateCompat.ACTION_REWIND or - PlaybackStateCompat.ACTION_STOP - - if (deviceSettings.allowSeekingOnWidget) { - playbackActions = playbackActions or PlaybackStateCompat.ACTION_SEEK_TO - } - - mediaSessionConnector.setEnabledPlaybackActions(playbackActions) + setMediaSessionConnectorPlaybackActions() mediaSessionConnector.setQueueNavigator(queueNavigator) mediaSessionConnector.setPlaybackPreparer(MediaSessionPlaybackPreparer(this)) @@ -515,6 +504,20 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { mediaSessionConnector.setCustomActionProviders(*customActionProviders.toTypedArray()) } + fun setMediaSessionConnectorPlaybackActions() { + var playbackActions = PlaybackStateCompat.ACTION_PLAY_PAUSE or + PlaybackStateCompat.ACTION_PLAY or + PlaybackStateCompat.ACTION_PAUSE or + PlaybackStateCompat.ACTION_FAST_FORWARD or + PlaybackStateCompat.ACTION_REWIND or + PlaybackStateCompat.ACTION_STOP + + if (deviceSettings.allowSeekingOnWidget) { + playbackActions = playbackActions or PlaybackStateCompat.ACTION_SEEK_TO + } + mediaSessionConnector.setEnabledPlaybackActions(playbackActions) + } + fun handlePlayerPlaybackError(errorMessage:String) { // On error and was attempting to direct play - fallback to transcode currentPlaybackSession?.let { playbackSession -> diff --git a/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsDatabase.kt b/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsDatabase.kt index f398589a..304cbdd6 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsDatabase.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsDatabase.kt @@ -1,5 +1,7 @@ package com.audiobookshelf.app.plugins +import android.os.Handler +import android.os.Looper import android.util.Log import com.audiobookshelf.app.MainActivity import com.audiobookshelf.app.data.* @@ -493,9 +495,16 @@ class AbsDatabase : Plugin() { fun updateDeviceSettings(call:PluginCall) { // Returns device data Log.d(tag, "updateDeviceSettings ${call.data}") val newDeviceSettings = jacksonMapper.readValue(call.data.toString()) - GlobalScope.launch(Dispatchers.IO) { + + Handler(Looper.getMainLooper()).post { DeviceManager.deviceData.deviceSettings = newDeviceSettings DeviceManager.dbManager.saveDeviceData(DeviceManager.deviceData) + + // Updates playback actions for media notification (handles media control seek locking setting) + if (mainActivity.isPlayerNotificationServiceInitialized()) { + mainActivity.foregroundService.setMediaSessionConnectorPlaybackActions() + } + call.resolve(JSObject(jacksonMapper.writeValueAsString(DeviceManager.deviceData))) } }