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