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?) { override fun onTaskRemoved(rootIntent: Intent?) {
Timber.i("Stopping the playback because we were swiped away") Timber.i("Stopping the playback because we were swiped away")
releasePlayerAndSession() releasePlayerAndSession()
super.onTaskRemoved(rootIntent)
} }
private fun releasePlayerAndSession() { private fun releasePlayerAndSession() {
// Broadcast that the service is being shutdown // Broadcast that the service is being shutdown
RxBus.stopServiceCommandPublisher.onNext(Unit) RxBus.stopServiceCommandPublisher.onNext(Unit)
// TODO Save the player state before shutdown
player.removeListener(listener) player.removeListener(listener)
player.release() player.release()
mediaLibrarySession.release() mediaLibrarySession.release()

View File

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

View File

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