[Android] Allow playing a playlist as audio

Nicolas Pomepuy git at videolan.org
Tue May 30 11:21:17 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon May 22 09:13:13 2023 +0200| [b33478ebe05c35e76e687bf62afa6de94fd050e9] | committer: Nicolas Pomepuy

Allow playing a playlist as audio

Fixes #2832

> https://code.videolan.org/videolan/vlc-android/commit/b33478ebe05c35e76e687bf62afa6de94fd050e9
---

 .../src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt     | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
index f527d5bfb4..f04c665b24 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
@@ -44,10 +44,7 @@ import com.google.android.material.tabs.TabLayout
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
-import org.videolan.medialibrary.interfaces.media.Album
-import org.videolan.medialibrary.interfaces.media.Artist
-import org.videolan.medialibrary.interfaces.media.Genre
-import org.videolan.medialibrary.interfaces.media.MediaWrapper
+import org.videolan.medialibrary.interfaces.media.*
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.resources.*
 import org.videolan.tools.*
@@ -392,6 +389,7 @@ abstract class BaseAudioBrowser<T : MedialibraryViewModel> : MediaBrowserFragmen
                 if ((item as? Genre)?.isFavorite == true) flags or CTX_FAV_REMOVE else flags or CTX_FAV_ADD
             }
             MediaLibraryItem.TYPE_PLAYLIST -> {
+                CTX_PLAY_AS_AUDIO or
                 (if (item.tracksCount > 2) CTX_PLAYLIST_ALBUM_FLAGS or CTX_PLAY_SHUFFLE else CTX_PLAYLIST_ALBUM_FLAGS) or if(item.isFavorite) CTX_FAV_REMOVE else CTX_FAV_ADD
             }
             else -> CTX_AUDIO_FLAGS
@@ -418,6 +416,14 @@ abstract class BaseAudioBrowser<T : MedialibraryViewModel> : MediaBrowserFragmen
         when (option) {
             CTX_PLAY -> MediaUtils.playTracks(requireActivity(), media, 0)
             CTX_PLAY_SHUFFLE -> MediaUtils.playTracks(requireActivity(), media, SecureRandom().nextInt(min(media.tracksCount, MEDIALIBRARY_PAGE_SIZE)), true)
+            CTX_PLAY_AS_AUDIO -> lifecycleScope.launch(Dispatchers.IO) {
+                (media as? Playlist)?.tracks?.let { trackArray ->
+                    MediaUtils.openList(requireActivity(), trackArray.map {
+                        it.addFlags(MediaWrapper.MEDIA_FORCE_AUDIO)
+                        it
+                    }.toList(), 0)
+                }
+            }
             CTX_INFORMATION -> showInfoDialog(media)
             CTX_DELETE -> removeItem(media)
             CTX_APPEND -> MediaUtils.appendMedia(requireActivity(), media.tracks)



More information about the Android mailing list