Fixed restarting after player service stop

This commit is contained in:
Nite 2023-01-04 14:33:19 +01:00
parent 10c9095f5f
commit 9319be2d5a
No known key found for this signature in database
GPG Key ID: 1D1AD59B1C6386C1
3 changed files with 10 additions and 7 deletions

View File

@ -85,12 +85,14 @@ class PlaybackService :
override fun onTaskRemoved(rootIntent: Intent?) {
Timber.i("Stopping the playback because we were swiped away")
releasePlayerAndSession()
super.onTaskRemoved(rootIntent)
}
private fun releasePlayerAndSession() {
// Broadcast that the service is being shutdown
RxBus.stopServiceCommandPublisher.onNext(Unit)
// TODO Save the player state before shutdown
player.removeListener(listener)
player.release()
mediaLibrarySession.release()

View File

@ -198,13 +198,10 @@ class MediaPlayerController(
}
rxBusSubscription += RxBus.shutdownCommandObservable.subscribe {
playbackStateSerializer.serializeNow(
playlist.map { it.toTrack() },
currentMediaItemIndex,
playerPosition,
isShufflePlayEnabled,
repeatMode
)
clear(false)
onDestroy()
}
rxBusSubscription += RxBus.stopServiceCommandObservable.subscribe {
clear(false)
onDestroy()
}

View File

@ -47,6 +47,9 @@ class MediaPlayerLifecycleSupport : KoinComponent {
rxBusSubscription += RxBus.shutdownCommandObservable.subscribe {
onDestroy()
}
rxBusSubscription += RxBus.stopServiceCommandObservable.subscribe {
onDestroy()
}
}
fun onCreate() {
@ -89,6 +92,7 @@ class MediaPlayerLifecycleSupport : KoinComponent {
private fun onDestroy() {
if (!created) return
rxBusSubscription.dispose()
applicationContext().unregisterReceiver(headsetEventReceiver)