diff --git a/app/src/main/java/de/christinecoenen/code/zapp/app/player/BackgroundPlayerService.kt b/app/src/main/java/de/christinecoenen/code/zapp/app/player/BackgroundPlayerService.kt index e14e76b6..770fb3be 100644 --- a/app/src/main/java/de/christinecoenen/code/zapp/app/player/BackgroundPlayerService.kt +++ b/app/src/main/java/de/christinecoenen/code/zapp/app/player/BackgroundPlayerService.kt @@ -8,10 +8,7 @@ import android.graphics.Bitmap import android.os.IBinder import androidx.core.app.NotificationCompat import androidx.core.content.ContextCompat -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.LifecycleOwner -import androidx.lifecycle.ServiceLifecycleDispatcher -import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.* import com.google.android.exoplayer2.ui.DefaultMediaDescriptionAdapter import com.google.android.exoplayer2.ui.PlayerNotificationManager import com.google.android.exoplayer2.ui.PlayerNotificationManager.BitmapCallback @@ -25,7 +22,7 @@ import kotlinx.coroutines.launch import org.koin.android.ext.android.inject import timber.log.Timber -class BackgroundPlayerService : IntentService("BackgroundPlayerService"), +class BackgroundPlayerService : LifecycleService(), MediaDescriptionAdapter, PlayerNotificationManager.NotificationListener, LifecycleOwner { @@ -60,8 +57,6 @@ class BackgroundPlayerService : IntentService("BackgroundPlayerService"), private val binder = Binder() - private val lifecycleDispatcher: ServiceLifecycleDispatcher = ServiceLifecycleDispatcher(this) - private var playerNotificationManager: PlayerNotificationManager? = null private var foregroundActivityIntent: Intent? = null private var isPlaybackInBackground = false @@ -74,7 +69,6 @@ class BackgroundPlayerService : IntentService("BackgroundPlayerService"), * So is is save to aquire locks and release them in [.onDestroy] */ override fun onCreate() { - lifecycleDispatcher.onServicePreSuperOnCreate() super.onCreate() lifecycleScope.launchWhenCreated { @@ -83,28 +77,16 @@ class BackgroundPlayerService : IntentService("BackgroundPlayerService"), } override fun onBind(intent: Intent): IBinder { - lifecycleDispatcher.onServicePreSuperOnBind() super.onBind(intent) - return binder } - override fun onStart(intent: Intent?, startId: Int) { - lifecycleDispatcher.onServicePreSuperOnStart() - super.onStart(intent, startId) - } - override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + super.onStartCommand(intent, flags, startId) handleIntent(intent) return Service.START_STICKY } - override fun onHandleIntent(intent: Intent?) {} - - override fun getLifecycle(): Lifecycle { - return lifecycleDispatcher.lifecycle - } - override fun onTaskRemoved(rootIntent: Intent) { super.onTaskRemoved(rootIntent) onDestroy() @@ -118,7 +100,6 @@ class BackgroundPlayerService : IntentService("BackgroundPlayerService"), playerNotificationManager?.setPlayer(null) } - lifecycleDispatcher.onServicePreSuperOnDestroy() super.onDestroy() }