[Android] Ensure start position is possible

Geoffrey Métais git at videolan.org
Mon Oct 29 15:31:10 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Oct 29 12:01:33 2018 +0100| [3a0d204be07d2e8de5af52411a8b7cef9b88ba8a] | committer: Geoffrey Métais

Ensure start position is possible

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

 vlc-android/src/org/videolan/vlc/media/MediaUtils.kt      |  4 ++--
 vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt | 11 +++++++----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt b/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
index 3554f9971..bf4996e96 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
+++ b/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
@@ -172,12 +172,12 @@ object MediaUtils : CoroutineScope {
         SuspendDialogCallback(context) { service ->
             val count = withContext(Dispatchers.IO) { model.getTotalCount() }
             fun play(list : List<MediaWrapper>) {
-                service.load(list, if (shuffle) Random().nextInt(count) else position)
+                service.load(list, if (shuffle) Random().nextInt(min(count, PLAYBACK_LOAD_SIZE)) else position)
                 if (shuffle && !service.isShuffling) service.shuffle()
             }
             when (count) {
                 0 -> return at SuspendDialogCallback
-                in 1..PAGE_SIZE -> play(withContext(Dispatchers.IO) { model.getAll().toList() })
+                in 1..PLAYBACK_LOAD_SIZE -> play(withContext(Dispatchers.IO) { model.getAll().toList() })
                 else -> {
                     var index = 0
                     while (index < count) {
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 70d9bdd90..b54c394df 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -8,7 +8,10 @@ import android.util.Log
 import android.widget.Toast
 import androidx.annotation.MainThread
 import androidx.lifecycle.MutableLiveData
-import kotlinx.coroutines.experimental.*
+import kotlinx.coroutines.experimental.CoroutineScope
+import kotlinx.coroutines.experimental.Dispatchers
+import kotlinx.coroutines.experimental.launch
+import kotlinx.coroutines.experimental.withContext
 import org.videolan.libvlc.Media
 import org.videolan.libvlc.MediaPlayer
 import org.videolan.libvlc.RendererItem
@@ -107,7 +110,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
         previous.clear()
         videoBackground = false
         launch {
-            launch(Dispatchers.IO) { for (media in list) mediaList.add(medialibrary.findMedia(media)) }.join()
+            withContext(Dispatchers.IO) { for (media in list) mediaList.add(medialibrary.findMedia(media)) }
             if (!hasMedia()) {
                 Log.w(TAG, "Warning: empty media list, nothing to play !")
                 return at launch
@@ -119,8 +122,8 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
             mediaList.addEventListener(this at PlaylistManager)
             stopAfter = -1
             clearABRepeat()
-                playIndex(position)
-                onPlaylistLoaded()
+            playIndex(currentIndex)
+            onPlaylistLoaded()
         }
     }
 



More information about the Android mailing list