diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/Loader.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/Loader.java index 4ff58b108c..64cafb42b9 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/Loader.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/Loader.java @@ -32,6 +32,7 @@ import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicBoolean; /** * Manages the background loading of {@link Loadable}s. @@ -56,6 +57,21 @@ public final class Loader implements LoaderErrorThrower { /** * Cancels the load. + * + *
Loadable implementations should ensure that a currently executing {@link #load()} call + * will exit reasonably quickly after this method is called. The {@link #load()} call may exit + * either by returning or by throwing an {@link IOException}. + * + *
If there is a currently executing {@link #load()} call, then the thread on which that call + * is being made will be interrupted immediately after the call to this method. Hence + * implementations do not need to (and should not attempt to) interrupt the loading thread + * themselves. + * + *
Although the loading thread will be interrupted, Loadable implementations should not use
+ * the interrupted status of the loading thread in {@link #load()} to determine whether the load
+ * has been canceled. This approach is not robust [Internal ref: b/79223737]. Instead,
+ * implementations should use their own flag to signal cancelation (for example, using {@link
+ * AtomicBoolean}).
*/
void cancelLoad();
@@ -307,10 +323,9 @@ public final class Loader implements LoaderErrorThrower {
private static final String TAG = "LoadTask";
private static final int MSG_START = 0;
- private static final int MSG_CANCEL = 1;
- private static final int MSG_END_OF_SOURCE = 2;
- private static final int MSG_IO_EXCEPTION = 3;
- private static final int MSG_FATAL_ERROR = 4;
+ private static final int MSG_FINISH = 1;
+ private static final int MSG_IO_EXCEPTION = 2;
+ private static final int MSG_FATAL_ERROR = 3;
public final int defaultMinRetryCount;
@@ -321,8 +336,8 @@ public final class Loader implements LoaderErrorThrower {
@Nullable private IOException currentError;
private int errorCount;
- @Nullable private volatile Thread executorThread;
- private volatile boolean canceled;
+ @Nullable private Thread executorThread;
+ private boolean canceled;
private volatile boolean released;
public LoadTask(Looper looper, T loadable, Loader.Callback