Clean up use of deprecated APIs

- Add @Deprecated on overrides of deprecated method.
- Suppress deprecation warnings where appropriate.
- Use non-deprecated alternatives where appropriate.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=210092434
This commit is contained in:
olly 2018-08-24 06:51:33 -07:00 committed by Oliver Woodman
parent 0da7f6ca08
commit 924a76d532
29 changed files with 106 additions and 23 deletions

View file

@ -76,9 +76,7 @@ import com.google.android.exoplayer2.util.Util;
contentMediaSource,
/* adMediaSourceFactory= */ this,
adsLoader,
playerView.getOverlayFrameLayout(),
/* eventHandler= */ null,
/* eventListener= */ null);
playerView.getOverlayFrameLayout());
// Prepare the player with the source.
player.seekTo(contentPosition);

View file

@ -213,7 +213,8 @@ public class SampleChooserActivity extends Activity
List<SampleGroup> result = new ArrayList<>();
Context context = getApplicationContext();
String userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
DataSource dataSource = new DefaultDataSource(context, null, userAgent, false);
DataSource dataSource =
new DefaultDataSource(context, userAgent, /* allowCrossProtocolRedirects= */ false);
for (String uri : uris) {
DataSpec dataSpec = new DataSpec(Uri.parse(uri));
InputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);

View file

@ -38,7 +38,11 @@ public final class RtmpDataSourceFactory implements DataSource.Factory {
@Override
public DataSource createDataSource() {
return new RtmpDataSource(listener);
RtmpDataSource dataSource = new RtmpDataSource();
if (listener != null) {
dataSource.addTransferListener(listener);
}
return dataSource;
}
}

View file

@ -154,6 +154,7 @@ public class DefaultLoadControl implements LoadControl {
}
/** Creates a {@link DefaultLoadControl}. */
@SuppressWarnings("deprecation")
public DefaultLoadControl createDefaultLoadControl() {
if (allocator == null) {
allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
@ -183,15 +184,15 @@ public class DefaultLoadControl implements LoadControl {
private int targetBufferSize;
private boolean isBuffering;
/**
* Constructs a new instance, using the {@code DEFAULT_*} constants defined in this class.
*/
/** Constructs a new instance, using the {@code DEFAULT_*} constants defined in this class. */
@SuppressWarnings("deprecation")
public DefaultLoadControl() {
this(new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE));
}
/** @deprecated Use {@link Builder} instead. */
@Deprecated
@SuppressWarnings("deprecation")
public DefaultLoadControl(DefaultAllocator allocator) {
this(
allocator,
@ -205,6 +206,7 @@ public class DefaultLoadControl implements LoadControl {
/** @deprecated Use {@link Builder} instead. */
@Deprecated
@SuppressWarnings("deprecation")
public DefaultLoadControl(
DefaultAllocator allocator,
int minBufferMs,

View file

@ -82,7 +82,7 @@ public class DefaultRenderersFactory implements RenderersFactory {
protected static final int MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY = 50;
private final Context context;
@Nullable private final DrmSessionManager<FrameworkMediaCrypto> drmSessionManager;
private final @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager;
private final @ExtensionRendererMode int extensionRendererMode;
private final long allowedVideoJoiningTimeMs;
@ -98,6 +98,7 @@ public class DefaultRenderersFactory implements RenderersFactory {
* directly to {@link SimpleExoPlayer} or {@link ExoPlayerFactory}.
*/
@Deprecated
@SuppressWarnings("deprecation")
public DefaultRenderersFactory(
Context context, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
this(context, drmSessionManager, EXTENSION_RENDERER_MODE_OFF);
@ -111,7 +112,7 @@ public class DefaultRenderersFactory implements RenderersFactory {
*/
public DefaultRenderersFactory(
Context context, @ExtensionRendererMode int extensionRendererMode) {
this(context, null, extensionRendererMode, DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS);
this(context, extensionRendererMode, DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS);
}
/**
@ -119,6 +120,7 @@ public class DefaultRenderersFactory implements RenderersFactory {
* DrmSessionManager} directly to {@link SimpleExoPlayer} or {@link ExoPlayerFactory}.
*/
@Deprecated
@SuppressWarnings("deprecation")
public DefaultRenderersFactory(
Context context,
@Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
@ -138,7 +140,10 @@ public class DefaultRenderersFactory implements RenderersFactory {
Context context,
@ExtensionRendererMode int extensionRendererMode,
long allowedVideoJoiningTimeMs) {
this(context, null, extensionRendererMode, allowedVideoJoiningTimeMs);
this.context = context;
this.extensionRendererMode = extensionRendererMode;
this.allowedVideoJoiningTimeMs = allowedVideoJoiningTimeMs;
this.drmSessionManager = null;
}
/**

View file

@ -227,6 +227,7 @@ public interface ExoPlayer extends Player {
/** @deprecated Use {@link #createMessage(PlayerMessage.Target)} instead. */
@Deprecated
@SuppressWarnings("deprecation")
void sendMessages(ExoPlayerMessage... messages);
/**
@ -234,6 +235,7 @@ public interface ExoPlayer extends Player {
* PlayerMessage#blockUntilDelivered()}.
*/
@Deprecated
@SuppressWarnings("deprecation")
void blockingSendMessages(ExoPlayerMessage... messages);
/**

View file

@ -415,6 +415,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
}
@Override
@Deprecated
@SuppressWarnings("deprecation")
public void sendMessages(ExoPlayerMessage... messages) {
for (ExoPlayerMessage message : messages) {
createMessage(message.target).setType(message.messageType).setPayload(message.message).send();
@ -432,6 +434,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
}
@Override
@Deprecated
@SuppressWarnings("deprecation")
public void blockingSendMessages(ExoPlayerMessage... messages) {
List<PlayerMessage> playerMessages = new ArrayList<>();
for (ExoPlayerMessage message : messages) {

View file

@ -392,6 +392,7 @@ public interface Player {
abstract class DefaultEventListener implements EventListener {
@Override
@SuppressWarnings("deprecation")
public void onTimelineChanged(
Timeline timeline, @Nullable Object manifest, @TimelineChangeReason int reason) {
// Call deprecated version. Otherwise, do nothing.

View file

@ -604,6 +604,7 @@ public class SimpleExoPlayer
* @deprecated Use {@link #addVideoListener(com.google.android.exoplayer2.video.VideoListener)}.
*/
@Deprecated
@SuppressWarnings("deprecation")
public void setVideoListener(VideoListener listener) {
videoListeners.clear();
if (listener != null) {
@ -619,6 +620,7 @@ public class SimpleExoPlayer
* #removeVideoListener(com.google.android.exoplayer2.video.VideoListener)}.
*/
@Deprecated
@SuppressWarnings("deprecation")
public void clearVideoListener(VideoListener listener) {
removeVideoListener(listener);
}
@ -709,6 +711,7 @@ public class SimpleExoPlayer
* information.
*/
@Deprecated
@SuppressWarnings("deprecation")
public void setVideoDebugListener(VideoRendererEventListener listener) {
videoDebugListeners.retainAll(Collections.singleton(analyticsCollector));
if (listener != null) {
@ -739,6 +742,7 @@ public class SimpleExoPlayer
* information.
*/
@Deprecated
@SuppressWarnings("deprecation")
public void setAudioDebugListener(AudioRendererEventListener listener) {
audioDebugListeners.retainAll(Collections.singleton(analyticsCollector));
if (listener != null) {
@ -939,6 +943,8 @@ public class SimpleExoPlayer
}
@Override
@Deprecated
@SuppressWarnings("deprecation")
public void sendMessages(ExoPlayerMessage... messages) {
player.sendMessages(messages);
}
@ -949,6 +955,8 @@ public class SimpleExoPlayer
}
@Override
@Deprecated
@SuppressWarnings("deprecation")
public void blockingSendMessages(ExoPlayerMessage... messages) {
player.blockingSendMessages(messages);
}

View file

@ -262,6 +262,7 @@ public final class ExtractorMediaSource extends BaseMediaSource
* @deprecated Use {@link Factory} instead.
*/
@Deprecated
@SuppressWarnings("deprecation")
public ExtractorMediaSource(
Uri uri,
DataSource.Factory dataSourceFactory,
@ -284,6 +285,7 @@ public final class ExtractorMediaSource extends BaseMediaSource
* @deprecated Use {@link Factory} instead.
*/
@Deprecated
@SuppressWarnings("deprecation")
public ExtractorMediaSource(
Uri uri,
DataSource.Factory dataSourceFactory,
@ -316,6 +318,7 @@ public final class ExtractorMediaSource extends BaseMediaSource
* @deprecated Use {@link Factory} instead.
*/
@Deprecated
@SuppressWarnings("deprecation")
public ExtractorMediaSource(
Uri uri,
DataSource.Factory dataSourceFactory,
@ -426,6 +429,8 @@ public final class ExtractorMediaSource extends BaseMediaSource
* Wraps a deprecated {@link EventListener}, invoking its callback from the equivalent callback in
* {@link MediaSourceEventListener}.
*/
@Deprecated
@SuppressWarnings("deprecation")
private static final class EventListenerWrapper extends DefaultMediaSourceEventListener {
private final EventListener eventListener;

View file

@ -197,6 +197,7 @@ public final class SingleSampleMediaSource extends BaseMediaSource {
* @deprecated Use {@link Factory} instead.
*/
@Deprecated
@SuppressWarnings("deprecation")
public SingleSampleMediaSource(
Uri uri, DataSource.Factory dataSourceFactory, Format format, long durationUs) {
this(
@ -249,6 +250,7 @@ public final class SingleSampleMediaSource extends BaseMediaSource {
* @deprecated Use {@link Factory} instead.
*/
@Deprecated
@SuppressWarnings("deprecation")
public SingleSampleMediaSource(
Uri uri,
DataSource.Factory dataSourceFactory,
@ -333,6 +335,8 @@ public final class SingleSampleMediaSource extends BaseMediaSource {
* Wraps a deprecated {@link EventListener}, invoking its callback from the equivalent callback in
* {@link MediaSourceEventListener}.
*/
@Deprecated
@SuppressWarnings("deprecation")
private static final class EventListenerWrapper extends DefaultMediaSourceEventListener {
private final EventListener eventListener;

View file

@ -1095,6 +1095,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
* directly passed to the player in ExoPlayerFactory.
*/
@Deprecated
@SuppressWarnings("deprecation")
public DefaultTrackSelector(BandwidthMeter bandwidthMeter) {
this(new AdaptiveTrackSelection.Factory(bandwidthMeter));
}

View file

@ -99,6 +99,7 @@ public abstract class MappingTrackSelector extends TrackSelector {
* each mapped track, indexed by renderer, track group and track (in that order).
* @param unmappedTrackGroups {@link TrackGroup}s not mapped to any renderer.
*/
@SuppressWarnings("deprecation")
/* package */ MappedTrackInfo(
int[] rendererTrackTypes,
TrackGroupArray[] rendererTrackGroups,

View file

@ -226,6 +226,7 @@ public final class DataSpec {
* @param key {@link #key}.
* @param flags {@link #flags}.
*/
@SuppressWarnings("deprecation")
public DataSpec(
Uri uri,
@HttpMethod int httpMethod,

View file

@ -142,6 +142,7 @@ public final class DefaultDataSource implements DataSource {
* #addTransferListener(TransferListener)}.
*/
@Deprecated
@SuppressWarnings("deprecation")
public DefaultDataSource(
Context context,
@Nullable TransferListener listener,
@ -167,6 +168,7 @@ public final class DefaultDataSource implements DataSource {
* #addTransferListener(TransferListener)}.
*/
@Deprecated
@SuppressWarnings("deprecation")
public DefaultDataSource(
Context context,
@Nullable TransferListener listener,

View file

@ -75,6 +75,11 @@ public final class DefaultDataSourceFactory implements Factory {
@Override
public DefaultDataSource createDataSource() {
return new DefaultDataSource(context, listener, baseDataSourceFactory.createDataSource());
DefaultDataSource dataSource =
new DefaultDataSource(context, baseDataSourceFactory.createDataSource());
if (listener != null) {
dataSource.addTransferListener(listener);
}
return dataSource;
}
}

View file

@ -168,6 +168,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
* #addTransferListener(TransferListener)}.
*/
@Deprecated
@SuppressWarnings("deprecation")
public DefaultHttpDataSource(
String userAgent,
@Nullable Predicate<String> contentTypePredicate,
@ -190,6 +191,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
* #addTransferListener(TransferListener)}.
*/
@Deprecated
@SuppressWarnings("deprecation")
public DefaultHttpDataSource(
String userAgent,
@Nullable Predicate<String> contentTypePredicate,

View file

@ -103,7 +103,17 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory {
@Override
protected DefaultHttpDataSource createDataSourceInternal(
HttpDataSource.RequestProperties defaultRequestProperties) {
return new DefaultHttpDataSource(userAgent, null, listener, connectTimeoutMillis,
readTimeoutMillis, allowCrossProtocolRedirects, defaultRequestProperties);
DefaultHttpDataSource dataSource =
new DefaultHttpDataSource(
userAgent,
/* contentTypePredicate= */ null,
connectTimeoutMillis,
readTimeoutMillis,
allowCrossProtocolRedirects,
defaultRequestProperties);
if (listener != null) {
dataSource.addTransferListener(listener);
}
return dataSource;
}
}

View file

@ -34,7 +34,11 @@ public final class FileDataSourceFactory implements DataSource.Factory {
@Override
public DataSource createDataSource() {
return new FileDataSource(listener);
FileDataSource dataSource = new FileDataSource();
if (listener != null) {
dataSource.addTransferListener(listener);
}
return dataSource;
}
}

View file

@ -95,6 +95,7 @@ public final class UdpDataSource extends BaseDataSource {
* @deprecated Use {@link #UdpDataSource()} and {@link #addTransferListener(TransferListener)}.
*/
@Deprecated
@SuppressWarnings("deprecation")
public UdpDataSource(@Nullable TransferListener listener) {
this(listener, DEFAULT_MAX_PACKET_SIZE);
}
@ -107,6 +108,7 @@ public final class UdpDataSource extends BaseDataSource {
* @deprecated Use {@link #UdpDataSource(int)} and {@link #addTransferListener(TransferListener)}.
*/
@Deprecated
@SuppressWarnings("deprecation")
public UdpDataSource(@Nullable TransferListener listener, int maxPacketSize) {
this(listener, maxPacketSize, DEFAULT_SOCKET_TIMEOUT_MILLIS);
}

View file

@ -96,7 +96,7 @@ public class DrmInitDataTest {
}
@Test
@Deprecated
@SuppressWarnings("deprecation")
public void testGetByUuid() {
// Basic matching.
DrmInitData testInitData = new DrmInitData(DATA_1, DATA_2);
@ -130,6 +130,7 @@ public class DrmInitDataTest {
}
@Test
@SuppressWarnings("deprecation")
public void testSchemeDatasWithSameUuid() {
DrmInitData testInitData = new DrmInitData(DATA_1, DATA_1B);
assertThat(testInitData.schemeDataCount).isEqualTo(2);

View file

@ -63,6 +63,7 @@ public final class AdaptiveTrackSelectionTest {
BandwidthMeter initialBandwidthMeter = mock(BandwidthMeter.class);
BandwidthMeter injectedBandwidthMeter = mock(BandwidthMeter.class);
Format format = videoFormat(/* bitrate= */ 500, /* width= */ 320, /* height= */ 240);
@SuppressWarnings("deprecation")
AdaptiveTrackSelection adaptiveTrackSelection =
new AdaptiveTrackSelection.Factory(initialBandwidthMeter)
.createTrackSelection(new TrackGroup(format), injectedBandwidthMeter, /* tracks= */ 0);

View file

@ -309,6 +309,7 @@ public final class HlsMediaSource extends BaseMediaSource
* @deprecated Use {@link Factory} instead.
*/
@Deprecated
@SuppressWarnings("deprecation")
public HlsMediaSource(
Uri manifestUri,
DataSource.Factory dataSourceFactory,
@ -334,6 +335,7 @@ public final class HlsMediaSource extends BaseMediaSource
* @deprecated Use {@link Factory} instead.
*/
@Deprecated
@SuppressWarnings("deprecation")
public HlsMediaSource(
Uri manifestUri,
DataSource.Factory dataSourceFactory,
@ -364,6 +366,7 @@ public final class HlsMediaSource extends BaseMediaSource
* @deprecated Use {@link Factory} instead.
*/
@Deprecated
@SuppressWarnings("deprecation")
public HlsMediaSource(
Uri manifestUri,
HlsDataSourceFactory dataSourceFactory,

View file

@ -330,6 +330,7 @@ public final class SsMediaSource extends BaseMediaSource
* @deprecated Use {@link Factory} instead.
*/
@Deprecated
@SuppressWarnings("deprecation")
public SsMediaSource(
SsManifest manifest,
SsChunkSource.Factory chunkSourceFactory,
@ -388,6 +389,7 @@ public final class SsMediaSource extends BaseMediaSource
* @deprecated Use {@link Factory} instead.
*/
@Deprecated
@SuppressWarnings("deprecation")
public SsMediaSource(
Uri manifestUri,
DataSource.Factory manifestDataSourceFactory,
@ -420,6 +422,7 @@ public final class SsMediaSource extends BaseMediaSource
* @deprecated Use {@link Factory} instead.
*/
@Deprecated
@SuppressWarnings("deprecation")
public SsMediaSource(
Uri manifestUri,
DataSource.Factory manifestDataSourceFactory,

View file

@ -34,10 +34,13 @@ public class PlaybackControlView extends PlayerControlView {
public interface VisibilityListener
extends com.google.android.exoplayer2.ui.PlayerControlView.VisibilityListener {}
@Deprecated
@SuppressWarnings("deprecation")
private static final class DefaultControlDispatcher
extends com.google.android.exoplayer2.DefaultControlDispatcher implements ControlDispatcher {}
/** @deprecated Use {@link com.google.android.exoplayer2.DefaultControlDispatcher}. */
@Deprecated
@SuppressWarnings("deprecation")
public static final ControlDispatcher DEFAULT_CONTROL_DISPATCHER = new DefaultControlDispatcher();
/** The default fast forward increment, in milliseconds. */

View file

@ -20,6 +20,7 @@ import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
/** @deprecated Use {@link PlayerView}. */
@ -45,7 +46,10 @@ public final class SimpleExoPlayerView extends PlayerView {
* @param player The player whose target view is being switched.
* @param oldPlayerView The old view to detach from the player.
* @param newPlayerView The new view to attach to the player.
* @deprecated Use {@link PlayerView#switchTargetView(Player, PlayerView, PlayerView)} instead.
*/
@Deprecated
@SuppressWarnings("deprecation")
public static void switchTargetView(
@NonNull SimpleExoPlayer player,
@Nullable SimpleExoPlayerView oldPlayerView,

View file

@ -25,6 +25,7 @@ import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.chunk.ChunkSampleStream;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.MimeTypes;
import java.util.ArrayList;
@ -142,13 +143,13 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
chunkSourceFactory.createChunkSource(trackSelection, durationUs, transferListener);
return new ChunkSampleStream<>(
MimeTypes.getTrackType(trackSelection.getSelectedFormat().sampleMimeType),
null,
null,
/* embeddedTrackTypes= */ null,
/* embeddedTrackFormats= */ null,
chunkSource,
this,
/* callback= */ this,
allocator,
0,
3,
/* positionUs= */ 0,
new DefaultLoadErrorHandlingPolicy(/* minimumLoadableRetryCount= */ 3),
eventDispatcher);
}

View file

@ -51,8 +51,9 @@ public class FakeTrackSelector extends DefaultTrackSelector {
int[] rendererMixedMimeTypeAdaptationSupports,
Parameters params)
throws ExoPlaybackException {
TrackSelection[] selections = new TrackSelection[mappedTrackInfo.length];
for (int i = 0; i < mappedTrackInfo.length; i++) {
int rendererCount = mappedTrackInfo.getRendererCount();
TrackSelection[] selections = new TrackSelection[rendererCount];
for (int i = 0; i < rendererCount; i++) {
TrackGroupArray trackGroupArray = mappedTrackInfo.getTrackGroups(i);
boolean hasTracks = trackGroupArray.length > 0;
selections[i] = hasTracks ? reuseOrCreateTrackSelection(trackGroupArray.get(0)) : null;

View file

@ -190,11 +190,15 @@ public abstract class StubExoPlayer implements ExoPlayer {
}
@Override
@Deprecated
@SuppressWarnings("deprecation")
public void sendMessages(ExoPlayerMessage... messages) {
throw new UnsupportedOperationException();
}
@Override
@Deprecated
@SuppressWarnings("deprecation")
public void blockingSendMessages(ExoPlayerMessage... messages) {
throw new UnsupportedOperationException();
}