|
@@ -54,7 +54,7 @@ import android.os.Binder as AndroidBinder
|
|
|
|
|
|
|
|
|
|
@Suppress("DEPRECATION")
|
|
@Suppress("DEPRECATION")
|
|
-class PlayerService : Service(), Player.Listener, PlaybackStatsListener.Callback,
|
|
|
|
|
|
+class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListener.Callback,
|
|
SharedPreferences.OnSharedPreferenceChangeListener {
|
|
SharedPreferences.OnSharedPreferenceChangeListener {
|
|
private lateinit var mediaSession: MediaSession
|
|
private lateinit var mediaSession: MediaSession
|
|
private lateinit var cache: SimpleCache
|
|
private lateinit var cache: SimpleCache
|
|
@@ -86,14 +86,19 @@ class PlayerService : Service(), Player.Listener, PlaybackStatsListener.Callback
|
|
|
|
|
|
private var isVolumeNormalizationEnabled = false
|
|
private var isVolumeNormalizationEnabled = false
|
|
private var isPersistentQueueEnabled = false
|
|
private var isPersistentQueueEnabled = false
|
|
|
|
+ override var isInvincibilityEnabled = false
|
|
|
|
|
|
private val binder = Binder()
|
|
private val binder = Binder()
|
|
|
|
|
|
private var isNotificationStarted = false
|
|
private var isNotificationStarted = false
|
|
|
|
|
|
|
|
+ override val notificationId: Int
|
|
|
|
+ get() = NotificationId
|
|
|
|
+
|
|
private lateinit var notificationActionReceiver: NotificationActionReceiver
|
|
private lateinit var notificationActionReceiver: NotificationActionReceiver
|
|
|
|
|
|
override fun onBind(intent: Intent?): AndroidBinder {
|
|
override fun onBind(intent: Intent?): AndroidBinder {
|
|
|
|
+ super.onBind(intent)
|
|
return binder
|
|
return binder
|
|
}
|
|
}
|
|
|
|
|
|
@@ -117,6 +122,7 @@ class PlayerService : Service(), Player.Listener, PlaybackStatsListener.Callback
|
|
val preferences = Preferences()
|
|
val preferences = Preferences()
|
|
isPersistentQueueEnabled = preferences.persistentQueue
|
|
isPersistentQueueEnabled = preferences.persistentQueue
|
|
isVolumeNormalizationEnabled = preferences.volumeNormalization
|
|
isVolumeNormalizationEnabled = preferences.volumeNormalization
|
|
|
|
+ isInvincibilityEnabled = preferences.isInvincibilityEnabled
|
|
|
|
|
|
val cacheEvictor = LeastRecentlyUsedCacheEvictor(preferences.exoPlayerDiskCacheMaxSizeBytes)
|
|
val cacheEvictor = LeastRecentlyUsedCacheEvictor(preferences.exoPlayerDiskCacheMaxSizeBytes)
|
|
cache = SimpleCache(cacheDir, cacheEvictor, StandaloneDatabaseProvider(this))
|
|
cache = SimpleCache(cacheDir, cacheEvictor, StandaloneDatabaseProvider(this))
|
|
@@ -190,6 +196,10 @@ class PlayerService : Service(), Player.Listener, PlaybackStatsListener.Callback
|
|
super.onDestroy()
|
|
super.onDestroy()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ override fun shouldBeInvincible(): Boolean {
|
|
|
|
+ return !player.shouldBePlaying
|
|
|
|
+ }
|
|
|
|
+
|
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
if (bitmapProvider.setDefaultBitmap() && player.currentMediaItem != null) {
|
|
if (bitmapProvider.setDefaultBitmap() && player.currentMediaItem != null) {
|
|
notificationManager?.notify(NotificationId, notification())
|
|
notificationManager?.notify(NotificationId, notification())
|
|
@@ -332,10 +342,12 @@ class PlayerService : Service(), Player.Listener, PlaybackStatsListener.Callback
|
|
isNotificationStarted = true
|
|
isNotificationStarted = true
|
|
startForegroundService(this@PlayerService, intent<PlayerService>())
|
|
startForegroundService(this@PlayerService, intent<PlayerService>())
|
|
startForeground(NotificationId, notification())
|
|
startForeground(NotificationId, notification())
|
|
|
|
+ makeInvincible(false)
|
|
} else {
|
|
} else {
|
|
if (!player.shouldBePlaying) {
|
|
if (!player.shouldBePlaying) {
|
|
isNotificationStarted = false
|
|
isNotificationStarted = false
|
|
stopForeground(false)
|
|
stopForeground(false)
|
|
|
|
+ makeInvincible(true)
|
|
}
|
|
}
|
|
notificationManager?.notify(NotificationId, notification)
|
|
notificationManager?.notify(NotificationId, notification)
|
|
}
|
|
}
|
|
@@ -348,10 +360,12 @@ class PlayerService : Service(), Player.Listener, PlaybackStatsListener.Callback
|
|
sharedPreferences.getBoolean(key, isPersistentQueueEnabled)
|
|
sharedPreferences.getBoolean(key, isPersistentQueueEnabled)
|
|
Preferences.Keys.volumeNormalization -> isVolumeNormalizationEnabled =
|
|
Preferences.Keys.volumeNormalization -> isVolumeNormalizationEnabled =
|
|
sharedPreferences.getBoolean(key, isVolumeNormalizationEnabled)
|
|
sharedPreferences.getBoolean(key, isVolumeNormalizationEnabled)
|
|
|
|
+ Preferences.Keys.isInvincibilityEnabled -> isInvincibilityEnabled =
|
|
|
|
+ sharedPreferences.getBoolean(key, isInvincibilityEnabled)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private fun notification(): Notification? {
|
|
|
|
|
|
+ override fun notification(): Notification? {
|
|
if (player.currentMediaItem == null) return null
|
|
if (player.currentMediaItem == null) return null
|
|
|
|
|
|
val playIntent = Action.play.pendingIntent
|
|
val playIntent = Action.play.pendingIntent
|