[Android] Thread songs loading in TV music browser

Geoffrey Métais git at videolan.org
Mon Jul 31 16:17:02 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jul 31 16:00:13 2017 +0200| [55d58c69ad60a3ae703e93e4a0c35b58acd426eb] | committer: Geoffrey Métais

Thread songs loading in TV music browser

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

 .../vlc/gui/tv/browser/SongsBrowserFragment.java   | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/SongsBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/SongsBrowserFragment.java
index a45a18654..64465c1bd 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/SongsBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/SongsBrowserFragment.java
@@ -52,12 +52,22 @@ public class SongsBrowserFragment extends SortedBrowserFragment {
 
     @Override
     protected void browse() {
-        mSongs = VLCApplication.getMLInstance().getAudio();
-        for (int i = 0 ; i < mSongs.length ; ++i) {
-            addMedia(mSongs[i]);
-            mMediaIndex.put(mSongs[i].getLocation(), i);
-        }
-        sort();
+        VLCApplication.runBackground(new Runnable() {
+            @Override
+            public void run() {
+                mSongs = VLCApplication.getMLInstance().getAudio();
+                VLCApplication.runOnMainThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        for (int i = 0 ; i < mSongs.length ; ++i) {
+                            addMedia(mSongs[i]);
+                            mMediaIndex.put(mSongs[i].getLocation(), i);
+                        }
+                        sort();
+                    }
+                });
+            }
+        });
     }
 
     protected void sort(){



More information about the Android mailing list