mirror of
https://github.com/samsonjs/media.git
synced 2026-03-31 10:25:48 +00:00
Make callback Handler instantiation consistent
Most of our components that have Handler instances for calling back to application code instantiate the Handler using Util.getLooper in the constructor. This makes the two components that do something else consistent with that model. PiperOrigin-RevId: 241545575
This commit is contained in:
parent
7c265dfb3a
commit
ee7bf4b0ee
2 changed files with 8 additions and 13 deletions
|
|
@ -18,7 +18,6 @@ package com.google.android.exoplayer2.offline;
|
|||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.Pair;
|
||||
|
|
@ -315,10 +314,10 @@ public final class DownloadHelper {
|
|||
private final DefaultTrackSelector trackSelector;
|
||||
private final RendererCapabilities[] rendererCapabilities;
|
||||
private final SparseIntArray scratchSet;
|
||||
private final Handler callbackHandler;
|
||||
|
||||
private boolean isPreparedWithMedia;
|
||||
private @MonotonicNonNull Callback callback;
|
||||
private @MonotonicNonNull Handler callbackHandler;
|
||||
private @MonotonicNonNull MediaPreparer mediaPreparer;
|
||||
private TrackGroupArray @MonotonicNonNull [] trackGroupArrays;
|
||||
private MappedTrackInfo @MonotonicNonNull [] mappedTrackInfos;
|
||||
|
|
@ -354,20 +353,18 @@ public final class DownloadHelper {
|
|||
this.scratchSet = new SparseIntArray();
|
||||
trackSelector.setParameters(trackSelectorParameters);
|
||||
trackSelector.init(/* listener= */ () -> {}, new DummyBandwidthMeter());
|
||||
callbackHandler = new Handler(Util.getLooper());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the helper for starting a download.
|
||||
*
|
||||
* @param callback A callback to be notified when preparation completes or fails. The callback
|
||||
* will be invoked on the calling thread unless that thread does not have an associated {@link
|
||||
* Looper}, in which case it will be called on the application's main thread.
|
||||
* @param callback A callback to be notified when preparation completes or fails.
|
||||
* @throws IllegalStateException If the download helper has already been prepared.
|
||||
*/
|
||||
public void prepare(Callback callback) {
|
||||
Assertions.checkState(this.callback == null);
|
||||
this.callback = callback;
|
||||
callbackHandler = new Handler(Util.getLooper());
|
||||
if (mediaSource != null) {
|
||||
mediaPreparer = new MediaPreparer(mediaSource, /* downloadHelper= */ this);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import android.os.Handler;
|
|||
import android.os.Looper;
|
||||
import android.os.PowerManager;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.Log;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
|
||||
|
|
@ -59,11 +58,12 @@ public final class RequirementsWatcher {
|
|||
private final Context context;
|
||||
private final Listener listener;
|
||||
private final Requirements requirements;
|
||||
private final Handler handler;
|
||||
|
||||
private DeviceStatusChangeReceiver receiver;
|
||||
|
||||
@Requirements.RequirementFlags private int notMetRequirements;
|
||||
private CapabilityValidatedCallback networkCallback;
|
||||
private Handler handler;
|
||||
|
||||
/**
|
||||
* @param context Any context.
|
||||
|
|
@ -71,9 +71,10 @@ public final class RequirementsWatcher {
|
|||
* @param requirements The requirements to watch.
|
||||
*/
|
||||
public RequirementsWatcher(Context context, Listener listener, Requirements requirements) {
|
||||
this.requirements = requirements;
|
||||
this.listener = listener;
|
||||
this.context = context.getApplicationContext();
|
||||
this.listener = listener;
|
||||
this.requirements = requirements;
|
||||
handler = new Handler(Util.getLooper());
|
||||
logd(this + " created");
|
||||
}
|
||||
|
||||
|
|
@ -85,9 +86,6 @@ public final class RequirementsWatcher {
|
|||
*/
|
||||
@Requirements.RequirementFlags
|
||||
public int start() {
|
||||
Assertions.checkNotNull(Looper.myLooper());
|
||||
handler = new Handler();
|
||||
|
||||
notMetRequirements = requirements.getNotMetRequirements(context);
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
|
|
|
|||
Loading…
Reference in a new issue