Cancel radio job when starting a new radio

This commit is contained in:
vfsfitvnm
2022-06-27 21:59:01 +02:00
parent 697c6b6379
commit 85f89ec799

View File

@@ -500,6 +500,8 @@ class PlayerService : Service(), Player.Listener, PlaybackStatsListener.Callback
val sleepTimerMillisLeft: StateFlow<Long?>?
get() = timerJob?.millisLeft
private var radioJob: Job? = null
fun startSleepTimer(delayMillis: Long) {
timerJob?.cancel()
@@ -532,6 +534,7 @@ class PlayerService : Service(), Player.Listener, PlaybackStatsListener.Callback
startRadio(endpoint= endpoint, justAdd = false)
private fun startRadio(endpoint: NavigationEndpoint.Endpoint.Watch?, justAdd: Boolean) {
radioJob?.cancel()
radio = null
YoutubePlayer.Radio(
endpoint?.videoId,
@@ -539,7 +542,7 @@ class PlayerService : Service(), Player.Listener, PlaybackStatsListener.Callback
endpoint?.playlistSetVideoId,
endpoint?.params
).let {
coroutineScope.launch(Dispatchers.Main) {
radioJob = coroutineScope.launch(Dispatchers.Main) {
if (justAdd) {
player.addMediaItems(it.process().drop(1))
} else {
@@ -551,6 +554,7 @@ class PlayerService : Service(), Player.Listener, PlaybackStatsListener.Callback
}
fun stopRadio() {
radioJob?.cancel()
radio = null
}
}