Use Util method to create Handler instead of using deprecated method.

Calls to new Handler() without arguments are deprecated as of the latest Android
version. Replace them by a Util.createHandler call similar to the ones we
already have.

PiperOrigin-RevId: 283532891
This commit is contained in:
tonihei 2019-12-03 14:25:54 +00:00 committed by bachinger
parent fb6a8a2c5d
commit 65c4a58825
16 changed files with 64 additions and 38 deletions

View file

@ -36,6 +36,7 @@ import com.google.android.exoplayer2.Player.DiscontinuityReason;
import com.google.android.exoplayer2.Player.TimelineChangeReason; import com.google.android.exoplayer2.Player.TimelineChangeReason;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.util.ErrorMessageProvider; import com.google.android.exoplayer2.util.ErrorMessageProvider;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoListener; import com.google.android.exoplayer2.video.VideoListener;
/** Leanback {@code PlayerAdapter} implementation for {@link Player}. */ /** Leanback {@code PlayerAdapter} implementation for {@link Player}. */
@ -71,7 +72,7 @@ public final class LeanbackPlayerAdapter extends PlayerAdapter implements Runnab
this.context = context; this.context = context;
this.player = player; this.player = player;
this.updatePeriodMs = updatePeriodMs; this.updatePeriodMs = updatePeriodMs;
handler = new Handler(); handler = Util.createHandler();
componentListener = new ComponentListener(); componentListener = new ComponentListener();
controlDispatcher = new DefaultControlDispatcher(); controlDispatcher = new DefaultControlDispatcher();
} }

View file

@ -427,7 +427,7 @@ import java.util.Set;
(source, timeline) -> playlistInfoListener.onPlaylistUpdateRequested(); (source, timeline) -> playlistInfoListener.onPlaylistUpdateRequested();
MediaSourceEventListener eventListener = new ForwardingEventListener(holder); MediaSourceEventListener eventListener = new ForwardingEventListener(holder);
childSources.put(holder, new MediaSourceAndListener(mediaSource, caller, eventListener)); childSources.put(holder, new MediaSourceAndListener(mediaSource, caller, eventListener));
mediaSource.addEventListener(new Handler(), eventListener); mediaSource.addEventListener(Util.createHandler(), eventListener);
mediaSource.prepareSource(caller, mediaTransferListener); mediaSource.prepareSource(caller, mediaTransferListener);
} }

View file

@ -46,7 +46,7 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
@CallSuper @CallSuper
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) { protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
this.mediaTransferListener = mediaTransferListener; this.mediaTransferListener = mediaTransferListener;
eventHandler = new Handler(); eventHandler = Util.createHandler();
} }
@Override @Override

View file

@ -189,7 +189,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
.onContinueLoadingRequested(ProgressiveMediaPeriod.this); .onContinueLoadingRequested(ProgressiveMediaPeriod.this);
} }
}; };
handler = new Handler(); handler = Util.createHandler();
sampleQueueTrackIds = new TrackId[0]; sampleQueueTrackIds = new TrackId[0];
sampleQueues = new SampleQueue[0]; sampleQueues = new SampleQueue[0];
pendingResetPositionUs = C.TIME_UNSET; pendingResetPositionUs = C.TIME_UNSET;

View file

@ -37,6 +37,7 @@ import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec; import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
@ -365,7 +366,7 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
* events on the external event listener thread. * events on the external event listener thread.
*/ */
public ComponentListener() { public ComponentListener() {
playerHandler = new Handler(); playerHandler = Util.createHandler();
} }
/** Releases the component listener. */ /** Releases the component listener. */

View file

@ -366,6 +366,17 @@ public final class Util {
/* length= */ second.length); /* length= */ second.length);
return concatenation; return concatenation;
} }
/**
* Creates a {@link Handler} on the current {@link Looper} thread.
*
* <p>If the current thread doesn't have a {@link Looper}, the application's main thread {@link
* Looper} is used.
*/
public static Handler createHandler() {
return createHandler(/* callback= */ null);
}
/** /**
* Creates a {@link Handler} with the specified {@link Handler.Callback} on the current {@link * Creates a {@link Handler} with the specified {@link Handler.Callback} on the current {@link
* Looper} thread. The method accepts partially initialized objects as callback under the * Looper} thread. The method accepts partially initialized objects as callback under the
@ -375,10 +386,11 @@ public final class Util {
* <p>If the current thread doesn't have a {@link Looper}, the application's main thread {@link * <p>If the current thread doesn't have a {@link Looper}, the application's main thread {@link
* Looper} is used. * Looper} is used.
* *
* @param callback A {@link Handler.Callback}. May be a partially initialized class. * @param callback A {@link Handler.Callback}. May be a partially initialized class, or null if no
* callback is required.
* @return A {@link Handler} with the specified callback on the current {@link Looper} thread. * @return A {@link Handler} with the specified callback on the current {@link Looper} thread.
*/ */
public static Handler createHandler(Handler.@UnknownInitialization Callback callback) { public static Handler createHandler(@Nullable Handler.@UnknownInitialization Callback callback) {
return createHandler(getLooper(), callback); return createHandler(getLooper(), callback);
} }
@ -389,12 +401,13 @@ public final class Util {
* initialized. * initialized.
* *
* @param looper A {@link Looper} to run the callback on. * @param looper A {@link Looper} to run the callback on.
* @param callback A {@link Handler.Callback}. May be a partially initialized class. * @param callback A {@link Handler.Callback}. May be a partially initialized class, or null if no
* callback is required.
* @return A {@link Handler} with the specified callback on the current {@link Looper} thread. * @return A {@link Handler} with the specified callback on the current {@link Looper} thread.
*/ */
@SuppressWarnings({"nullness:argument.type.incompatible", "nullness:return.type.incompatible"}) @SuppressWarnings({"nullness:argument.type.incompatible", "nullness:return.type.incompatible"})
public static Handler createHandler( public static Handler createHandler(
Looper looper, Handler.@UnknownInitialization Callback callback) { Looper looper, @Nullable Handler.@UnknownInitialization Callback callback) {
return new Handler(looper, callback); return new Handler(looper, callback);
} }
@ -1988,7 +2001,7 @@ public final class Util {
@Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) { @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
Renderer[] renderers = Renderer[] renderers =
renderersFactory.createRenderers( renderersFactory.createRenderers(
new Handler(), Util.createHandler(),
new VideoRendererEventListener() {}, new VideoRendererEventListener() {},
new AudioRendererEventListener() {}, new AudioRendererEventListener() {},
(cues) -> {}, (cues) -> {},

View file

@ -1799,7 +1799,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
private final class OnFrameRenderedListenerV23 implements MediaCodec.OnFrameRenderedListener { private final class OnFrameRenderedListenerV23 implements MediaCodec.OnFrameRenderedListener {
private OnFrameRenderedListenerV23(MediaCodec codec) { private OnFrameRenderedListenerV23(MediaCodec codec) {
codec.setOnFrameRenderedListener(this, new Handler()); codec.setOnFrameRenderedListener(/* listener= */ this, Util.createHandler());
} }
@Override @Override

View file

@ -18,7 +18,6 @@ package com.google.android.exoplayer2.source;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import android.os.Handler;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
@ -37,6 +36,7 @@ import com.google.android.exoplayer2.testutil.MediaSourceTestRunner;
import com.google.android.exoplayer2.testutil.TimelineAsserts; import com.google.android.exoplayer2.testutil.TimelineAsserts;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -553,7 +553,7 @@ public final class ClippingMediaSourceTest {
testRunner.runOnPlaybackThread( testRunner.runOnPlaybackThread(
() -> () ->
clippingMediaSource.addEventListener( clippingMediaSource.addEventListener(
new Handler(), Util.createHandler(),
new MediaSourceEventListener() { new MediaSourceEventListener() {
@Override @Override
public void onDownstreamFormatChanged( public void onDownstreamFormatChanged(

View file

@ -19,7 +19,6 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import android.os.Handler;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
@ -34,6 +33,7 @@ import com.google.android.exoplayer2.testutil.FakeTimeline;
import com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition; import com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition;
import com.google.android.exoplayer2.testutil.MediaSourceTestRunner; import com.google.android.exoplayer2.testutil.MediaSourceTestRunner;
import com.google.android.exoplayer2.testutil.TimelineAsserts; import com.google.android.exoplayer2.testutil.TimelineAsserts;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -414,7 +414,7 @@ public final class ConcatenatingMediaSourceTest {
dummyMainThread.runOnMainThread( dummyMainThread.runOnMainThread(
() -> () ->
mediaSource.addMediaSource( mediaSource.addMediaSource(
createFakeMediaSource(), new Handler(), runnableInvoked::countDown)); createFakeMediaSource(), Util.createHandler(), runnableInvoked::countDown));
runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS); runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS);
dummyMainThread.release(); dummyMainThread.release();
@ -430,7 +430,7 @@ public final class ConcatenatingMediaSourceTest {
() -> () ->
mediaSource.addMediaSources( mediaSource.addMediaSources(
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}), Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
new Handler(), Util.createHandler(),
runnableInvoked::countDown)); runnableInvoked::countDown));
runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS); runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS);
dummyMainThread.release(); dummyMainThread.release();
@ -446,7 +446,10 @@ public final class ConcatenatingMediaSourceTest {
dummyMainThread.runOnMainThread( dummyMainThread.runOnMainThread(
() -> () ->
mediaSource.addMediaSource( mediaSource.addMediaSource(
/* index */ 0, createFakeMediaSource(), new Handler(), runnableInvoked::countDown)); /* index */ 0,
createFakeMediaSource(),
Util.createHandler(),
runnableInvoked::countDown));
runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS); runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS);
dummyMainThread.release(); dummyMainThread.release();
@ -463,7 +466,7 @@ public final class ConcatenatingMediaSourceTest {
mediaSource.addMediaSources( mediaSource.addMediaSources(
/* index */ 0, /* index */ 0,
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}), Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
new Handler(), Util.createHandler(),
runnableInvoked::countDown)); runnableInvoked::countDown));
runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS); runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS);
dummyMainThread.release(); dummyMainThread.release();
@ -479,7 +482,8 @@ public final class ConcatenatingMediaSourceTest {
dummyMainThread.runOnMainThread( dummyMainThread.runOnMainThread(
() -> { () -> {
mediaSource.addMediaSource(createFakeMediaSource()); mediaSource.addMediaSource(createFakeMediaSource());
mediaSource.removeMediaSource(/* index */ 0, new Handler(), runnableInvoked::countDown); mediaSource.removeMediaSource(
/* index */ 0, Util.createHandler(), runnableInvoked::countDown);
}); });
runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS); runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS);
dummyMainThread.release(); dummyMainThread.release();
@ -497,7 +501,7 @@ public final class ConcatenatingMediaSourceTest {
mediaSource.addMediaSources( mediaSource.addMediaSources(
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()})); Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}));
mediaSource.moveMediaSource( mediaSource.moveMediaSource(
/* fromIndex */ 1, /* toIndex */ 0, new Handler(), runnableInvoked::countDown); /* fromIndex */ 1, /* toIndex */ 0, Util.createHandler(), runnableInvoked::countDown);
}); });
runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS); runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS);
dummyMainThread.release(); dummyMainThread.release();
@ -513,7 +517,8 @@ public final class ConcatenatingMediaSourceTest {
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner); final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
dummyMainThread.runOnMainThread( dummyMainThread.runOnMainThread(
() -> () ->
mediaSource.addMediaSource(createFakeMediaSource(), new Handler(), timelineGrabber)); mediaSource.addMediaSource(
createFakeMediaSource(), Util.createHandler(), timelineGrabber));
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking(); Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
assertThat(timeline.getWindowCount()).isEqualTo(1); assertThat(timeline.getWindowCount()).isEqualTo(1);
} finally { } finally {
@ -532,7 +537,7 @@ public final class ConcatenatingMediaSourceTest {
mediaSource.addMediaSources( mediaSource.addMediaSources(
Arrays.asList( Arrays.asList(
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}), new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
new Handler(), Util.createHandler(),
timelineGrabber)); timelineGrabber));
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking(); Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
assertThat(timeline.getWindowCount()).isEqualTo(2); assertThat(timeline.getWindowCount()).isEqualTo(2);
@ -550,7 +555,7 @@ public final class ConcatenatingMediaSourceTest {
dummyMainThread.runOnMainThread( dummyMainThread.runOnMainThread(
() -> () ->
mediaSource.addMediaSource( mediaSource.addMediaSource(
/* index */ 0, createFakeMediaSource(), new Handler(), timelineGrabber)); /* index */ 0, createFakeMediaSource(), Util.createHandler(), timelineGrabber));
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking(); Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
assertThat(timeline.getWindowCount()).isEqualTo(1); assertThat(timeline.getWindowCount()).isEqualTo(1);
} finally { } finally {
@ -570,7 +575,7 @@ public final class ConcatenatingMediaSourceTest {
/* index */ 0, /* index */ 0,
Arrays.asList( Arrays.asList(
new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}), new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
new Handler(), Util.createHandler(),
timelineGrabber)); timelineGrabber));
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking(); Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
assertThat(timeline.getWindowCount()).isEqualTo(2); assertThat(timeline.getWindowCount()).isEqualTo(2);
@ -589,7 +594,8 @@ public final class ConcatenatingMediaSourceTest {
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner); final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
dummyMainThread.runOnMainThread( dummyMainThread.runOnMainThread(
() -> mediaSource.removeMediaSource(/* index */ 0, new Handler(), timelineGrabber)); () ->
mediaSource.removeMediaSource(/* index */ 0, Util.createHandler(), timelineGrabber));
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking(); Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
assertThat(timeline.getWindowCount()).isEqualTo(0); assertThat(timeline.getWindowCount()).isEqualTo(0);
} finally { } finally {
@ -613,7 +619,7 @@ public final class ConcatenatingMediaSourceTest {
dummyMainThread.runOnMainThread( dummyMainThread.runOnMainThread(
() -> () ->
mediaSource.moveMediaSource( mediaSource.moveMediaSource(
/* fromIndex */ 1, /* toIndex */ 0, new Handler(), timelineGrabber)); /* fromIndex */ 1, /* toIndex */ 0, Util.createHandler(), timelineGrabber));
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking(); Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
assertThat(timeline.getWindowCount()).isEqualTo(2); assertThat(timeline.getWindowCount()).isEqualTo(2);
} finally { } finally {
@ -634,7 +640,7 @@ public final class ConcatenatingMediaSourceTest {
mediaSource.moveMediaSource( mediaSource.moveMediaSource(
/* currentIndex= */ 0, /* currentIndex= */ 0,
/* newIndex= */ 1, /* newIndex= */ 1,
new Handler(), Util.createHandler(),
callbackCalledCondition::countDown); callbackCalledCondition::countDown);
mediaSource.releaseSource(caller); mediaSource.releaseSource(caller);
}); });
@ -886,7 +892,7 @@ public final class ConcatenatingMediaSourceTest {
testRunner.prepareSource(); testRunner.prepareSource();
final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner); final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
dummyMainThread.runOnMainThread(() -> mediaSource.clear(new Handler(), timelineGrabber)); dummyMainThread.runOnMainThread(() -> mediaSource.clear(Util.createHandler(), timelineGrabber));
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking(); Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
assertThat(timeline.isEmpty()).isTrue(); assertThat(timeline.isEmpty()).isTrue();
@ -1038,7 +1044,7 @@ public final class ConcatenatingMediaSourceTest {
() -> () ->
mediaSource.setShuffleOrder( mediaSource.setShuffleOrder(
new ShuffleOrder.UnshuffledShuffleOrder(/* length= */ 0), new ShuffleOrder.UnshuffledShuffleOrder(/* length= */ 0),
new Handler(), Util.createHandler(),
runnableInvoked::countDown)); runnableInvoked::countDown));
runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS); runnableInvoked.await(MediaSourceTestRunner.TIMEOUT_MS, TimeUnit.MILLISECONDS);
dummyMainThread.release(); dummyMainThread.release();
@ -1058,7 +1064,7 @@ public final class ConcatenatingMediaSourceTest {
() -> () ->
mediaSource.setShuffleOrder( mediaSource.setShuffleOrder(
new ShuffleOrder.UnshuffledShuffleOrder(/* length= */ 3), new ShuffleOrder.UnshuffledShuffleOrder(/* length= */ 3),
new Handler(), Util.createHandler(),
timelineGrabber)); timelineGrabber));
Timeline timeline = timelineGrabber.assertTimelineChangeBlocking(); Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
assertThat(timeline.getFirstWindowIndex(/* shuffleModeEnabled= */ true)).isEqualTo(0); assertThat(timeline.getFirstWindowIndex(/* shuffleModeEnabled= */ true)).isEqualTo(0);

View file

@ -663,7 +663,7 @@ public final class DashMediaSource extends BaseMediaSource {
} else { } else {
dataSource = manifestDataSourceFactory.createDataSource(); dataSource = manifestDataSourceFactory.createDataSource();
loader = new Loader("Loader:DashMediaSource"); loader = new Loader("Loader:DashMediaSource");
handler = new Handler(); handler = Util.createHandler();
startLoadingManifest(); startLoadingManifest();
} }
} }

View file

@ -219,7 +219,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
@SuppressWarnings("nullness:methodref.receiver.bound.invalid") @SuppressWarnings("nullness:methodref.receiver.bound.invalid")
Runnable onTracksEndedRunnable = this::onTracksEnded; Runnable onTracksEndedRunnable = this::onTracksEnded;
this.onTracksEndedRunnable = onTracksEndedRunnable; this.onTracksEndedRunnable = onTracksEndedRunnable;
handler = new Handler(); handler = Util.createHandler();
lastSeekPositionUs = positionUs; lastSeekPositionUs = positionUs;
pendingResetPositionUs = positionUs; pendingResetPositionUs = positionUs;
} }

View file

@ -31,6 +31,7 @@ import com.google.android.exoplayer2.upstream.Loader;
import com.google.android.exoplayer2.upstream.Loader.LoadErrorAction; import com.google.android.exoplayer2.upstream.Loader.LoadErrorAction;
import com.google.android.exoplayer2.upstream.ParsingLoadable; import com.google.android.exoplayer2.upstream.ParsingLoadable;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -117,7 +118,7 @@ public final class DefaultHlsPlaylistTracker
Uri initialPlaylistUri, Uri initialPlaylistUri,
EventDispatcher eventDispatcher, EventDispatcher eventDispatcher,
PrimaryPlaylistListener primaryPlaylistListener) { PrimaryPlaylistListener primaryPlaylistListener) {
this.playlistRefreshHandler = new Handler(); this.playlistRefreshHandler = Util.createHandler();
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;
this.primaryPlaylistListener = primaryPlaylistListener; this.primaryPlaylistListener = primaryPlaylistListener;
ParsingLoadable<HlsPlaylist> masterPlaylistLoadable = ParsingLoadable<HlsPlaylist> masterPlaylistLoadable =

View file

@ -50,6 +50,7 @@ import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
import com.google.android.exoplayer2.upstream.ParsingLoadable; import com.google.android.exoplayer2.upstream.ParsingLoadable;
import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -560,7 +561,7 @@ public final class SsMediaSource extends BaseMediaSource
manifestDataSource = manifestDataSourceFactory.createDataSource(); manifestDataSource = manifestDataSourceFactory.createDataSource();
manifestLoader = new Loader("Loader:Manifest"); manifestLoader = new Loader("Loader:Manifest");
manifestLoaderErrorThrower = manifestLoader; manifestLoaderErrorThrower = manifestLoader;
manifestRefreshHandler = new Handler(); manifestRefreshHandler = Util.createHandler();
startLoadingManifest(); startLoadingManifest();
} }
} }

View file

@ -37,6 +37,7 @@ import com.google.android.exoplayer2.trackselection.DefaultTrackSelector.Paramet
import com.google.android.exoplayer2.util.ConditionVariable; import com.google.android.exoplayer2.util.ConditionVariable;
import com.google.android.exoplayer2.util.HandlerWrapper; import com.google.android.exoplayer2.util.HandlerWrapper;
import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.Util;
/** Base class for actions to perform during playback tests. */ /** Base class for actions to perform during playback tests. */
public abstract class Action { public abstract class Action {
@ -422,7 +423,7 @@ public abstract class Action {
} else { } else {
message.setPosition(positionMs); message.setPosition(positionMs);
} }
message.setHandler(new Handler()); message.setHandler(Util.createHandler());
message.setDeleteAfterDelivery(deleteAfterDelivery); message.setDeleteAfterDelivery(deleteAfterDelivery);
message.send(); message.send();
} }
@ -503,7 +504,7 @@ public abstract class Action {
final Surface surface, final Surface surface,
final HandlerWrapper handler, final HandlerWrapper handler,
final ActionNode nextAction) { final ActionNode nextAction) {
Handler testThreadHandler = new Handler(); Handler testThreadHandler = Util.createHandler();
// Schedule a message on the playback thread to ensure the player is paused immediately. // Schedule a message on the playback thread to ensure the player is paused immediately.
player player
.createMessage( .createMessage(

View file

@ -30,6 +30,7 @@ import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.DataSpec; import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
@ -126,7 +127,7 @@ public class FakeMediaPeriod implements MediaPeriod {
SystemClock.elapsedRealtime()); SystemClock.elapsedRealtime());
prepareCallback = callback; prepareCallback = callback;
if (deferOnPrepared) { if (deferOnPrepared) {
playerHandler = new Handler(); playerHandler = Util.createHandler();
} else { } else {
finishPreparation(); finishPreparation();
} }

View file

@ -37,6 +37,7 @@ import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.DataSpec; import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -97,7 +98,7 @@ public class FakeMediaSource extends BaseMediaSource {
transferListener = mediaTransferListener; transferListener = mediaTransferListener;
preparedSource = true; preparedSource = true;
releasedSource = false; releasedSource = false;
sourceInfoRefreshHandler = new Handler(); sourceInfoRefreshHandler = Util.createHandler();
if (timeline != null) { if (timeline != null) {
finishSourcePreparation(); finishSourcePreparation();
} }