mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-29 22:57:16 +02:00
Update:Android foreground service updates
This commit is contained in:
+21
-4
@@ -1,21 +1,37 @@
|
|||||||
package com.audiobookshelf.app.player
|
package com.audiobookshelf.app.player
|
||||||
|
|
||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
|
import android.content.pm.ServiceInfo
|
||||||
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.google.android.exoplayer2.ui.PlayerNotificationManager
|
import com.google.android.exoplayer2.ui.PlayerNotificationManager
|
||||||
|
|
||||||
class PlayerNotificationListener(var playerNotificationService:PlayerNotificationService) : PlayerNotificationManager.NotificationListener {
|
class PlayerNotificationListener(var playerNotificationService:PlayerNotificationService) : PlayerNotificationManager.NotificationListener {
|
||||||
var tag = "PlayerNotificationListener"
|
var tag = "PlayerNotificationListener"
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
var isForegroundService = false
|
||||||
|
}
|
||||||
|
|
||||||
override fun onNotificationPosted(
|
override fun onNotificationPosted(
|
||||||
notificationId: Int,
|
notificationId: Int,
|
||||||
notification: Notification,
|
notification: Notification,
|
||||||
onGoing: Boolean) {
|
onGoing: Boolean) {
|
||||||
|
|
||||||
// Start foreground service
|
if (onGoing && !isForegroundService) {
|
||||||
Log.d(tag, "Notification Posted $notificationId - Start Foreground | $notification")
|
// Start foreground service
|
||||||
PlayerNotificationService.isClosed = false
|
Log.d(tag, "Notification Posted $notificationId - Start Foreground | $notification")
|
||||||
playerNotificationService.startForeground(notificationId, notification)
|
PlayerNotificationService.isClosed = false
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
playerNotificationService.startForeground(notificationId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK)
|
||||||
|
} else {
|
||||||
|
playerNotificationService.startForeground(notificationId, notification)
|
||||||
|
}
|
||||||
|
isForegroundService = true
|
||||||
|
} else {
|
||||||
|
Log.d(tag, "Notification posted $notificationId, not starting foreground - onGoing=$onGoing | isForegroundService=$isForegroundService")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNotificationCancelled(
|
override fun onNotificationCancelled(
|
||||||
@@ -39,5 +55,6 @@ class PlayerNotificationListener(var playerNotificationService:PlayerNotificatio
|
|||||||
PlayerNotificationService.isSwitchingPlayer = false
|
PlayerNotificationService.isSwitchingPlayer = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
isForegroundService = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,7 +175,6 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||||||
castPlayer?.release()
|
castPlayer?.release()
|
||||||
mediaSession.release()
|
mediaSession.release()
|
||||||
mediaProgressSyncer.reset()
|
mediaProgressSyncer.reset()
|
||||||
Log.d(tag, "onDestroy")
|
|
||||||
isStarted = false
|
isStarted = false
|
||||||
|
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ ext {
|
|||||||
cordovaAndroidVersion = '10.1.1'
|
cordovaAndroidVersion = '10.1.1'
|
||||||
androidx_car_version = '1.0.0-alpha7'
|
androidx_car_version = '1.0.0-alpha7'
|
||||||
androidx_core_ktx_version = '1.7.0'
|
androidx_core_ktx_version = '1.7.0'
|
||||||
androidx_media_version = '1.5.0'
|
androidx_media_version = '1.6.0'
|
||||||
androidx_preference_version = '1.1.1'
|
androidx_preference_version = '1.1.1'
|
||||||
androidx_test_runner_version = '1.3.0'
|
androidx_test_runner_version = '1.3.0'
|
||||||
arch_lifecycle_version = '2.2.0'
|
arch_lifecycle_version = '2.2.0'
|
||||||
|
|||||||
Reference in New Issue
Block a user