diff --git a/src/android/MediaObject.java b/src/android/MediaObject.java index 054aea0..5e5debd 100644 --- a/src/android/MediaObject.java +++ b/src/android/MediaObject.java @@ -7,7 +7,10 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.Serializable; +import java.util.Iterator; import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; @@ -76,7 +79,7 @@ public class MediaObject implements Serializable { /** * 获取所有分块 */ - private LinkedList mMediaList = new LinkedList(); + private List mMediaList = new CopyOnWriteArrayList(); private Lock lock = new ReentrantLock(); @@ -225,9 +228,10 @@ public class MediaObject implements Serializable { if(mMediaList == null){ return; } - synchronized (mMediaList){ - for (MediaPart part : mMediaList) { - consumer.accept(part); + Iterator iterator = mMediaList.iterator(); + synchronized (iterator){ + while(iterator.hasNext()){ + consumer.accept(iterator.next()); } } } @@ -401,7 +405,7 @@ public class MediaObject implements Serializable { FileUtils.deleteDir(mOutputDirectory); } - public LinkedList getMedaParts() { + public List getMedaParts() { return mMediaList; }