From 31ba48e5398d0329d68239267833e17a9de3a8c7 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 23 Dec 2023 10:48:46 +0100 Subject: [PATCH] fix: crash when playing deleted playlist in background --- .../libretube/ui/sheets/PlaylistOptionsBottomSheet.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt index 17f531508..58d9319b7 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt @@ -68,8 +68,12 @@ class PlaylistOptionsBottomSheet : BaseBottomSheet() { // play the playlist in the background R.string.playOnBackground -> { val playlist = withContext(Dispatchers.IO) { - PlaylistsHelper.getPlaylist(playlistId) + runCatching { PlaylistsHelper.getPlaylist(playlistId) } + }.getOrElse { + context?.toastFromMainDispatcher(R.string.error) + return@setSimpleItems } + playlist.relatedStreams.firstOrNull()?.let { BackgroundHelper.playOnBackground( requireContext(),