diff --git a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt index e41a359ce..85cfe7373 100644 --- a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt +++ b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt @@ -364,7 +364,8 @@ class BackgroundMode : LifecycleService() { * destroy the [BackgroundMode] foreground service */ override fun onDestroy() { - // clear the playing queue + // clear and reset the playing queue + PlayingQueue.clear() PlayingQueue.resetToDefaults() if (this::nowPlayingNotification.isInitialized) nowPlayingNotification.destroySelfAndPlayer() diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index cc08295e6..9c168b65a 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -584,6 +584,8 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions { saveWatchPosition() + PlayingQueue.clear() + // release the player nowPlayingNotification.destroySelfAndPlayer() @@ -644,18 +646,18 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions { // reset the comments to become reloaded later commentsViewModel.reset() - lifecycleScope.launchWhenCreated { + lifecycleScope.launch(Dispatchers.IO) { streams = try { RetrofitInstance.api.getStreams(videoId!!) } catch (e: IOException) { Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_LONG).show() - return@launchWhenCreated + return@launch } catch (e: HttpException) { val errorMessage = e.response()?.errorBody()?.string()?.runCatching { JsonHelper.json.decodeFromString(this).message }?.getOrNull() ?: context?.getString(R.string.server_error) ?: "" Toast.makeText(context, errorMessage, Toast.LENGTH_LONG).show() - return@launchWhenCreated + return@launch } if (PlayingQueue.isEmpty()) {