[Android] PlaylistManager: Prevent IndexOutOfBoundsException

Geoffrey Métais git at videolan.org
Tue Jun 25 15:20:57 CEST 2019


vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jun 25 13:46:36 2019 +0200| [da4e3728a7402f02ab76385cff606ef0cf8eb5fe] | committer: Geoffrey Métais

PlaylistManager: Prevent IndexOutOfBoundsException

(cherry picked from commit 07d4002053a5846aec3384dd44ca94827a59e043)

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

 vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 80529f611..282897058 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -27,6 +27,7 @@ import org.videolan.vlc.gui.preferences.PreferencesFragment
 import org.videolan.vlc.gui.video.VideoPlayerActivity
 import org.videolan.vlc.util.*
 import java.util.*
+import kotlin.math.max
 
 private const val TAG = "VLC/PlaylistManager"
 private const val PREVIOUS_LIMIT_DELAY = 5000L
@@ -160,7 +161,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
             // load playlist
             shuffling = settings.getBoolean(if (audio) "audio_shuffling" else "media_shuffling", false)
             repeating = settings.getInt(if (audio) "audio_repeating" else "media_repeating", REPEAT_NONE)
-            val position = settings.getInt(if (audio) "position_in_audio_list" else "position_in_media_list", 0)
+            val position = max(0, settings.getInt(if (audio) "position_in_audio_list" else "position_in_media_list", 0))
             savedTime = settings.getLong(if (audio) "position_in_song" else "position_in_media", -1)
             if (!audio && position < playList.size && settings.getBoolean(PreferencesActivity.VIDEO_PAUSED, false)) {
                 playList[position].addFlags(MediaWrapper.MEDIA_PAUSED)



More information about the Android mailing list