[Android] Fix "opened_position" intent extra, to use for index based playlist opening

popy popy git at videolan.org
Wed May 3 12:43:54 UTC 2023


vlc-android | branch: master | popy popy <tobias.diendorfer at gmail.com> | Wed May  3 12:43:53 2023 +0000| [8880ccca3bae2b39d0f0ae3185fe78b3a1841611] | committer: Duncan McNamara

Fix "opened_position" intent extra, to use for index based playlist opening

> https://code.videolan.org/videolan/vlc-android/commit/8880ccca3bae2b39d0f0ae3185fe78b3a1841611
---

 .../src/org/videolan/vlc/PlaybackService.kt           |  2 +-
 .../org/videolan/vlc/gui/video/VideoPlayerActivity.kt |  2 +-
 .../src/org/videolan/vlc/media/PlaylistManager.kt     | 19 ++++++++++++++++---
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index c2a440de36..ef4def5c5b 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -1438,7 +1438,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner, CoroutineSc
     }
 
     @MainThread
-    fun load(media: MediaWrapper) = load(listOf(media), 0)
+    fun load(media: MediaWrapper, position: Int = 0) = load(listOf(media), position)
 
     /**
      * Play a media from the media list (playlist)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index f7af07476f..bf42330ce7 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -2035,7 +2035,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
                         if (displayManager.isPrimary) service.flush()
                         onPlaying()
                     } else service.playIndex(positionInPlaylist)
-                } else service.load(media)
+                } else service.load(media, positionInPlaylist)
 
                 // Get the title
                 if (itemTitle == null && "content" != uri.scheme) title = uri.lastPathSegment
diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 53e21b9a67..b77cd1e7be 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -57,6 +57,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     var currentIndex = -1
     private var nextIndex = -1
     private var prevIndex = -1
+    var startupIndex = -1    
     private var previous = Stack<Int>()
     var stopAfter = -1
     var repeating = PlaybackStateCompat.REPEAT_MODE_NONE
@@ -169,7 +170,12 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
             Log.w(TAG, "Warning: empty media list, nothing to play !")
             return
         }
-        currentIndex = if (isValidPosition(position)) position else 0
+        if (isValidPosition(position)) {
+            currentIndex = position
+        } else {
+            currentIndex = 0
+            startupIndex = if(position >= 0) position else 0
+        }
 
         // Add handler after loading the list
         mediaList.addEventListener(this at PlaylistManager)
@@ -268,7 +274,14 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
         val size = mediaList.size()
         if (force || repeating != PlaybackStateCompat.REPEAT_MODE_ONE) {
             previous.push(currentIndex)
-            currentIndex = nextIndex
+            //startup index given?
+            if (startupIndex != -1) {
+                currentIndex = startupIndex
+                startupIndex = -1
+            } else {
+                //no startup index given, use next
+                currentIndex = nextIndex
+            }
             if (size == 0 || currentIndex < 0 || currentIndex >= size) {
                 Log.w(TAG, "Warning: invalid next index, aborted !")
                 stop()
@@ -1123,4 +1136,4 @@ class DelayValues(var start: Long = -1L, var stop: Long = -1L)
 class WaitConfirmation(val title: String, val index: Int, val flags: Int)
 enum class VideoResumeStatus {
     ALWAYS, ASK, NEVER
-}
\ No newline at end of file
+}



More information about the Android mailing list