[Android] Remove iterator

Geoffrey Métais git at videolan.org
Wed May 25 18:43:43 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed May 25 18:42:43 2016 +0200| [564c6840f1c16180f00c518d59f51310c06444d7] | committer: Geoffrey Métais

Remove iterator

Avoid ConcurrentModificationException

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

 .../src/org/videolan/vlc/media/MediaLibrary.java      | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/media/MediaLibrary.java
index 920db94..3f5a22b 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaLibrary.java
@@ -169,7 +169,10 @@ public class MediaLibrary {
 
     public ArrayList<MediaWrapper> getVideoItems() {
         ArrayList<MediaWrapper> videoItems = new ArrayList<>();
-        for (MediaWrapper item : mItemList) {
+        MediaWrapper item;
+        int count = mItemList.size();
+        for (int i = 0; i < count; ++i) {
+            item = mItemList.get(i);
             if (item != null && item.getType() == MediaWrapper.TYPE_VIDEO) {
                 videoItems.add(item);
             }
@@ -179,7 +182,10 @@ public class MediaLibrary {
 
     public ArrayList<MediaWrapper> getAudioItems() {
         ArrayList<MediaWrapper> audioItems = new ArrayList<>();
-        for (MediaWrapper item : mItemList) {
+        MediaWrapper item;
+        int count = mItemList.size();
+        for (int i = 0; i < count; ++i) {
+            item = mItemList.get(i);
             if (item.getType() == MediaWrapper.TYPE_AUDIO) {
                 audioItems.add(item);
             }
@@ -189,11 +195,12 @@ public class MediaLibrary {
 
     public ArrayList<MediaWrapper> getPlaylistFilesItems() {
         ArrayList<MediaWrapper> playlistItems = new ArrayList<>();
-        for (int i = 0; i < mItemList.size(); i++) {
-            MediaWrapper item = mItemList.get(i);
-            if (item.getType() == MediaWrapper.TYPE_PLAYLIST) {
+        MediaWrapper item;
+        int count = mItemList.size();
+        for (int i = 0; i < count; ++i) {
+            item = mItemList.get(i);
+            if (item.getType() == MediaWrapper.TYPE_PLAYLIST)
                 playlistItems.add(item);
-            }
         }
         return playlistItems;
     }



More information about the Android mailing list