[Android] Only list and play audio files in history

Robert Stone git at videolan.org
Thu Nov 5 06:55:10 CET 2020


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Mon Nov  2 23:35:38 2020 -0800| [4e021a23ece56735965385450f2a59a105933c21] | committer: Nicolas Pomepuy

Only list and play audio files in history

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

 .../src/org/videolan/vlc/MediaSessionCallback.kt     |  2 +-
 .../org/videolan/vlc/media/MediaSessionBrowser.kt    | 20 +++++++++++++-------
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
index 3967d21d5..4be9605bd 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
@@ -80,7 +80,7 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
                     }
                 }
                 mediaId == MediaSessionBrowser.ID_HISTORY -> {
-                    val tracks = context.getFromMl { lastMediaPlayed()?.toList() }
+                    val tracks = context.getFromMl { lastMediaPlayed()?.toList()?.filter { MediaSessionBrowser.isMediaAudio(it) } }
                     if (!tracks.isNullOrEmpty() && isActive) {
                         val mediaList = tracks.subList(0, tracks.size.coerceAtMost(MediaSessionBrowser.MAX_HISTORY_SIZE))
                         playbackService.load(mediaList, 0)
diff --git a/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt b/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
index 80f3669c7..fe8ff7a31 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
@@ -258,12 +258,14 @@ class MediaSessionBrowser : ExtensionManagerActivity {
                         results.add(MediaBrowserCompat.MediaItem(lastAddedMediaDesc, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE))
                         /* History */
                         if (Settings.getInstance(context).getBoolean(PLAYBACK_HISTORY, true)) {
-                            val lastMediaPlayed = ml.lastMediaPlayed();
-                            val historyCover: Bitmap? = getHomeImage("history", lastMediaPlayed)
-                            val historyMediaDesc = getPlayAllBuilder(res, ID_HISTORY, lastMediaPlayed.size.coerceAtMost(MAX_HISTORY_SIZE), historyCover)
-                                    .setTitle(res.getString(R.string.history))
-                                    .build()
-                            results.add(MediaBrowserCompat.MediaItem(historyMediaDesc, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE))
+                            val lastMediaPlayed = ml.lastMediaPlayed()?.toList()?.filter { isMediaAudio(it) }
+                            if (!lastMediaPlayed.isNullOrEmpty()) {
+                                val historyCover: Bitmap? = getHomeImage("history", lastMediaPlayed.toTypedArray())
+                                val historyMediaDesc = getPlayAllBuilder(res, ID_HISTORY, lastMediaPlayed.size.coerceAtMost(MAX_HISTORY_SIZE), historyCover)
+                                        .setTitle(res.getString(R.string.history))
+                                        .build()
+                                results.add(MediaBrowserCompat.MediaItem(historyMediaDesc, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE))
+                            }
                         }
                     }
                     ID_LIBRARY -> {
@@ -314,7 +316,7 @@ class MediaSessionBrowser : ExtensionManagerActivity {
                     }
                     ID_HISTORY -> {
                         limitSize = true
-                        list = ml.lastMediaPlayed()
+                        list = ml.lastMediaPlayed()?.toList()?.filter { isMediaAudio(it) }?.toTypedArray()
                         if (list != null && list.size > 1) {
                             val playAllMediaDesc = getPlayAllBuilder(res, parentId, list.size.coerceAtMost(MAX_HISTORY_SIZE)).build()
                             results.add(MediaBrowserCompat.MediaItem(playAllMediaDesc, MediaBrowserCompat.MediaItem.FLAG_PLAYABLE))
@@ -473,6 +475,10 @@ class MediaSessionBrowser : ExtensionManagerActivity {
             return "${prefix}_${libraryItem.id}"
         }
 
+        fun isMediaAudio(libraryItem: MediaLibraryItem): Boolean {
+            return libraryItem.itemType == MediaLibraryItem.TYPE_MEDIA && (libraryItem as MediaWrapper).type == MediaWrapper.TYPE_AUDIO
+        }
+
         private fun getPlayAllBuilder(res: Resources, mediaId: String, trackCount: Int, cover: Bitmap? = null): MediaDescriptionCompat.Builder {
             return MediaDescriptionCompat.Builder()
                     .setMediaId(mediaId)



More information about the Android mailing list