[Android] Prevent IllegalArgumentException in PlaylistManager due to a race condition
Nicolas Pomepuy
git at videolan.org
Tue Oct 26 06:45:23 UTC 2021
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Oct 20 08:57:52 2021 +0200| [e2eaec5194d28102af98f49ed0f3ff1fab853b43] | committer: Nicolas Pomepuy
Prevent IllegalArgumentException in PlaylistManager due to a race condition
> https://code.videolan.org/videolan/vlc-android/commit/e2eaec5194d28102af98f49ed0f3ff1fab853b43
---
.../src/org/videolan/vlc/media/PlaylistManager.kt | 34 ++++++++++++----------
1 file changed, 19 insertions(+), 15 deletions(-)
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 700a972b4..71bde085b 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -634,21 +634,25 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
}
}
- fun previousTotalTime() = when {
- mediaList.size() == 0 || currentIndex < 0 -> {
- 0
- }
- shuffling -> {
- mediaList.copy.asSequence()
- .filterIndexed { index, _ -> previous.contains(index) }
- .map { it.length }
- .sum()
- }
- else -> {
- mediaList.copy.asSequence()
- .take(currentIndex)
- .map { it.length }
- .sum()
+ fun previousTotalTime(): Long {
+ val index = currentIndex
+ val copy = mediaList.copy
+ return when {
+ copy.size == 0 || index < 0 -> {
+ 0
+ }
+ shuffling -> {
+ copy.asSequence()
+ .filterIndexed { index, _ -> previous.contains(index) }
+ .map { it.length }
+ .sum()
+ }
+ else -> {
+ copy.asSequence()
+ .take(index)
+ .map { it.length }
+ .sum()
+ }
}
}
More information about the Android
mailing list