Merge branch 'fix/service-stop' into 'develop'

Fixed restarting after player service stop

Closes #858

See merge request ultrasonic/ultrasonic!898
This commit is contained in:
Nite 2023-01-04 13:43:15 +00:00
commit dd5bcba69c
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)