[Android] Avoid loading tracks from main thread
Geoffrey Métais
git at videolan.org
Thu Sep 27 11:22:06 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Sep 26 18:01:20 2018 +0200| [2a46c8bf919c8ee0834efd5b333a254df10632a1] | committer: Geoffrey Métais
Avoid loading tracks from main thread
> https://code.videolan.org/videolan/vlc-android/commit/2a46c8bf919c8ee0834efd5b333a254df10632a1
---
vlc-android/src/org/videolan/vlc/gui/InfoActivity.java | 2 +-
vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java | 5 ++---
vlc-android/src/org/videolan/vlc/gui/SearchActivity.java | 2 +-
vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java | 2 +-
vlc-android/src/org/videolan/vlc/media/MediaUtils.kt | 5 ++++-
5 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/InfoActivity.java b/vlc-android/src/org/videolan/vlc/gui/InfoActivity.java
index e338de7d2..4e139248c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/InfoActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/InfoActivity.java
@@ -186,7 +186,7 @@ public class InfoActivity extends AudioPlayerContainerActivity implements View.O
@Override
public void onClick(View v) {
- MediaUtils.INSTANCE.openArray(this, mItem.getTracks(), 0);
+ MediaUtils.INSTANCE.playTracks(this, mItem, 0);
finish();
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
index 5b99fffa6..b1bce60f9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
@@ -69,7 +69,6 @@ import org.videolan.vlc.media.PlaylistManager;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.FileUtils;
-import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.WorkersKt;
import org.videolan.vlc.viewmodels.paged.MLPagedModel;
import org.videolan.vlc.viewmodels.paged.PagedTracksModel;
@@ -188,7 +187,7 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
if (mActionMode != null) {
mAdapter.getMultiSelectHelper().toggleSelection(position);
invalidateActionMode();
- } else MediaUtils.INSTANCE.openArray(this, mPlaylist.getTracks(), position);
+ } else MediaUtils.INSTANCE.playTracks(this, mPlaylist, position);
}
@Override
@@ -367,7 +366,7 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
@Override
public void onClick(View v) {
- MediaUtils.INSTANCE.openArray(this, mPlaylist.getTracks(), 0);
+ MediaUtils.INSTANCE.playTracks(this, mPlaylist, 0);
}
private void removeFromPlaylist(final List<MediaWrapper> list){
diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
index cfb05335a..3dd9f6400 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
@@ -141,7 +141,7 @@ public class SearchActivity extends AppCompatActivity implements TextWatcher, Te
finish();
}
public void onItemClick(MediaLibraryItem item) {
- MediaUtils.INSTANCE.openArray(SearchActivity.this, item.getTracks(), 0);
+ MediaUtils.INSTANCE.playTracks(SearchActivity.this, item, 0);
finish();
}
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java b/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
index ec6d951d9..56cf6a27e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
@@ -195,7 +195,7 @@ public abstract class BaseAudioBrowser extends MediaBrowserFragment<MLPagedModel
if (media == null) return;
switch (option){
case Constants.CTX_PLAY:
- MediaUtils.INSTANCE.openArray(requireActivity(), media.getTracks(), 0);
+ MediaUtils.INSTANCE.playTracks(requireActivity(), media, 0);
break;
case Constants.CTX_PLAY_ALL:
MediaUtils.INSTANCE.playAll(requireContext(), getViewModel(), position, false);
diff --git a/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt b/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
index 7f9e07c77..92b4477cb 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
+++ b/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
@@ -17,6 +17,7 @@ import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.channels.actor
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.Tools
+import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.medialibrary.media.Playlist
import org.videolan.vlc.PlaybackService
@@ -121,7 +122,9 @@ object MediaUtils {
}
}
- fun openArray(context: Context, array: Array<MediaWrapper>, position: Int) = openList(context, array.toList(), position)
+ fun playTracks(context: Context, item: MediaLibraryItem, position: Int) = GlobalScope.launch(Dispatchers.Main.immediate) {
+ openList(context, withContext(Dispatchers.IO) { item.tracks }.toList(), position)
+ }
fun playAll(context: Context?, model: MLPagedModel<MediaWrapper>, position: Int, shuffle: Boolean) {
if (context == null) return
More information about the Android
mailing list