[Android] Invoke getAllTracks more efficiently

Robert Stone git at videolan.org
Mon Jun 26 07:45:43 UTC 2023


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Mon Jun  5 21:10:28 2023 -0700| [95d0d64769cf691f906d0b3da0bc91463e44896b] | committer: Robert Stone

Invoke getAllTracks more efficiently

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

 .../vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt     | 12 +++---------
 .../src/org/videolan/vlc/gui/video/VideoStatsDelegate.kt     |  3 +--
 2 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt
index 4dbc75171b..78b4c5ca10 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt
@@ -266,17 +266,11 @@ class InfoModel : ViewModel() {
             mediaFactory.getFromUri(libVlc, mw.uri).apply { parse() }
         }
         if (!isActive) return at launch
-        var subs = false
-        val trackCount = media.getAllTracks().size
-        val tracks = LinkedList<IMedia.Track>()
-        for (i in 0 until trackCount) {
-            val track = media.getAllTracks()[i]
-            tracks.add(track)
-            subs = subs or (track.type == IMedia.Track.Type.Text)
-        }
+        val tracks = media.getAllTracks()
+        val subs = tracks.asReversed().any { it.type == IMedia.Track.Type.Text }
         media.release()
         hasSubs.value = subs
-        mediaTracks.value = tracks.toList()
+        mediaTracks.value = tracks
     }
 
     fun checkFile(mw: MediaWrapper) = viewModelScope.launch {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoStatsDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoStatsDelegate.kt
index 3cbdd43fcc..38d4e27260 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoStatsDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoStatsDelegate.kt
@@ -108,11 +108,10 @@ class VideoStatsDelegate(private val player: VideoPlayerActivity, val scrolling:
         if (lastMediaUri != media.uri) {
             lastMediaUri = media.uri
             binding.infoGrids.removeAllViews()
-            for (i in 0 until media.getAllTracks().size) {
+            for (track in media.getAllTracks()) {
                 val grid = GridLayout(player)
                 grid.columnCount = 2
 
-                val track = media.getAllTracks()[i]
                 if (track.bitrate > 0) addStreamGridView(grid, player.getString(R.string.bitrate), player.getString(R.string.bitrate_value, track.bitrate.toLong().readableSize()))
                 addStreamGridView(grid, player.getString(R.string.codec), track.codec)
                 if (track.language != null && !track.language.equals("und", ignoreCase = true))



More information about the Android mailing list