Deprecate Player.DefaultEventListener in favor of default no-ops in interface.
The DefaultEventListener was added for selective overrides. Now that Java 8 support is enabled, these selective listener overrides can be implemented more easily and more flexible using default methods. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=201695490
This commit is contained in:
parent
b031c3d6bb
commit
156e2317cc
@ -40,6 +40,8 @@
|
||||
`ExoPlayerFactory` ([#4278](https://github.com/google/ExoPlayer/issues/4278)).
|
||||
* Fix a bug where download cancellation was ignored
|
||||
([#4403](https://github.com/google/ExoPlayer/issues/4403)).
|
||||
* Deprecate `Player.DefaultEventListener` as selective listener overrides can
|
||||
be directly made with the `Player.EventListener` interface.
|
||||
|
||||
### 2.8.2 ###
|
||||
|
||||
|
@ -23,8 +23,8 @@ import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.DefaultRenderersFactory;
|
||||
import com.google.android.exoplayer2.ExoPlayerFactory;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.Player.DefaultEventListener;
|
||||
import com.google.android.exoplayer2.Player.DiscontinuityReason;
|
||||
import com.google.android.exoplayer2.Player.EventListener;
|
||||
import com.google.android.exoplayer2.Player.TimelineChangeReason;
|
||||
import com.google.android.exoplayer2.RenderersFactory;
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
@ -51,11 +51,9 @@ import com.google.android.gms.cast.MediaQueueItem;
|
||||
import com.google.android.gms.cast.framework.CastContext;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Manages players and an internal media queue for the ExoPlayer/Cast demo app.
|
||||
*/
|
||||
/* package */ final class PlayerManager extends DefaultEventListener
|
||||
implements CastPlayer.SessionAvailabilityListener {
|
||||
/** Manages players and an internal media queue for the ExoPlayer/Cast demo app. */
|
||||
/* package */ final class PlayerManager
|
||||
implements EventListener, CastPlayer.SessionAvailabilityListener {
|
||||
|
||||
/**
|
||||
* Listener for changes in the media queue playback position.
|
||||
|
@ -655,7 +655,7 @@ public class PlayerActivity extends Activity
|
||||
return false;
|
||||
}
|
||||
|
||||
private class PlayerEventListener extends Player.DefaultEventListener {
|
||||
private class PlayerEventListener implements Player.EventListener {
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
|
@ -64,8 +64,7 @@ public class FlacPlaybackTest extends InstrumentationTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestPlaybackRunnable extends Player.DefaultEventListener
|
||||
implements Runnable {
|
||||
private static class TestPlaybackRunnable implements Player.EventListener, Runnable {
|
||||
|
||||
private final Context context;
|
||||
private final Uri uri;
|
||||
|
@ -66,11 +66,15 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Loads ads using the IMA SDK. All methods are called on the main thread.
|
||||
*/
|
||||
public final class ImaAdsLoader extends Player.DefaultEventListener implements AdsLoader,
|
||||
VideoAdPlayer, ContentProgressProvider, AdErrorListener, AdsLoadedListener, AdEventListener {
|
||||
/** Loads ads using the IMA SDK. All methods are called on the main thread. */
|
||||
public final class ImaAdsLoader
|
||||
implements Player.EventListener,
|
||||
AdsLoader,
|
||||
VideoAdPlayer,
|
||||
ContentProgressProvider,
|
||||
AdErrorListener,
|
||||
AdsLoadedListener,
|
||||
AdEventListener {
|
||||
|
||||
static {
|
||||
ExoPlayerLibraryInfo.registerModule("goog.exo.ima");
|
||||
|
@ -248,8 +248,8 @@ public final class LeanbackPlayerAdapter extends PlayerAdapter implements Runnab
|
||||
surfaceHolderGlueHost.setSurfaceHolderCallback(null);
|
||||
}
|
||||
|
||||
private final class ComponentListener extends Player.DefaultEventListener
|
||||
implements SurfaceHolder.Callback, VideoListener {
|
||||
private final class ComponentListener
|
||||
implements Player.EventListener, SurfaceHolder.Callback, VideoListener {
|
||||
|
||||
// SurfaceHolder.Callback implementation.
|
||||
|
||||
|
@ -716,7 +716,7 @@ public final class MediaSessionConnector {
|
||||
}
|
||||
}
|
||||
|
||||
private class ExoPlayerEventListener extends Player.DefaultEventListener {
|
||||
private class ExoPlayerEventListener implements Player.EventListener {
|
||||
|
||||
private int currentWindowIndex;
|
||||
private int currentWindowCount;
|
||||
|
@ -64,8 +64,7 @@ public class OpusPlaybackTest extends InstrumentationTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestPlaybackRunnable extends Player.DefaultEventListener
|
||||
implements Runnable {
|
||||
private static class TestPlaybackRunnable implements Player.EventListener, Runnable {
|
||||
|
||||
private final Context context;
|
||||
private final Uri uri;
|
||||
|
@ -95,8 +95,7 @@ public class VpxPlaybackTest extends InstrumentationTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestPlaybackRunnable extends Player.DefaultEventListener
|
||||
implements Runnable {
|
||||
private static class TestPlaybackRunnable implements Player.EventListener, Runnable {
|
||||
|
||||
private final Context context;
|
||||
private final Uri uri;
|
||||
|
@ -215,23 +215,25 @@ public interface Player {
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener of changes in player state.
|
||||
* Listener of changes in player state. All methods have no-op default implementations to allow
|
||||
* selective overrides.
|
||||
*/
|
||||
interface EventListener {
|
||||
|
||||
/**
|
||||
* Called when the timeline and/or manifest has been refreshed.
|
||||
* <p>
|
||||
* Note that if the timeline has changed then a position discontinuity may also have occurred.
|
||||
* For example, the current period index may have changed as a result of periods being added or
|
||||
* removed from the timeline. This will <em>not</em> be reported via a separate call to
|
||||
*
|
||||
* <p>Note that if the timeline has changed then a position discontinuity may also have
|
||||
* occurred. For example, the current period index may have changed as a result of periods being
|
||||
* added or removed from the timeline. This will <em>not</em> be reported via a separate call to
|
||||
* {@link #onPositionDiscontinuity(int)}.
|
||||
*
|
||||
* @param timeline The latest timeline. Never null, but may be empty.
|
||||
* @param manifest The latest manifest. May be null.
|
||||
* @param reason The {@link TimelineChangeReason} responsible for this timeline change.
|
||||
*/
|
||||
void onTimelineChanged(Timeline timeline, Object manifest, @TimelineChangeReason int reason);
|
||||
default void onTimelineChanged(
|
||||
Timeline timeline, Object manifest, @TimelineChangeReason int reason) {}
|
||||
|
||||
/**
|
||||
* Called when the available or selected tracks change.
|
||||
@ -240,46 +242,47 @@ public interface Player {
|
||||
* @param trackSelections The track selections for each renderer. Never null and always of
|
||||
* length {@link #getRendererCount()}, but may contain null elements.
|
||||
*/
|
||||
void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections);
|
||||
default void onTracksChanged(
|
||||
TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {}
|
||||
|
||||
/**
|
||||
* Called when the player starts or stops loading the source.
|
||||
*
|
||||
* @param isLoading Whether the source is currently being loaded.
|
||||
*/
|
||||
void onLoadingChanged(boolean isLoading);
|
||||
default void onLoadingChanged(boolean isLoading) {}
|
||||
|
||||
/**
|
||||
* Called when the value returned from either {@link #getPlayWhenReady()} or
|
||||
* {@link #getPlaybackState()} changes.
|
||||
* Called when the value returned from either {@link #getPlayWhenReady()} or {@link
|
||||
* #getPlaybackState()} changes.
|
||||
*
|
||||
* @param playWhenReady Whether playback will proceed when ready.
|
||||
* @param playbackState One of the {@code STATE} constants.
|
||||
*/
|
||||
void onPlayerStateChanged(boolean playWhenReady, int playbackState);
|
||||
default void onPlayerStateChanged(boolean playWhenReady, int playbackState) {}
|
||||
|
||||
/**
|
||||
* Called when the value of {@link #getRepeatMode()} changes.
|
||||
*
|
||||
* @param repeatMode The {@link RepeatMode} used for playback.
|
||||
*/
|
||||
void onRepeatModeChanged(@RepeatMode int repeatMode);
|
||||
default void onRepeatModeChanged(@RepeatMode int repeatMode) {}
|
||||
|
||||
/**
|
||||
* Called when the value of {@link #getShuffleModeEnabled()} changes.
|
||||
*
|
||||
* @param shuffleModeEnabled Whether shuffling of windows is enabled.
|
||||
*/
|
||||
void onShuffleModeEnabledChanged(boolean shuffleModeEnabled);
|
||||
default void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {}
|
||||
|
||||
/**
|
||||
* Called when an error occurs. The playback state will transition to {@link #STATE_IDLE}
|
||||
* immediately after this method is called. The player instance can still be used, and
|
||||
* {@link #release()} must still be called on the player should it no longer be required.
|
||||
* immediately after this method is called. The player instance can still be used, and {@link
|
||||
* #release()} must still be called on the player should it no longer be required.
|
||||
*
|
||||
* @param error The error.
|
||||
*/
|
||||
void onPlayerError(ExoPlaybackException error);
|
||||
default void onPlayerError(ExoPlaybackException error) {}
|
||||
|
||||
/**
|
||||
* Called when a position discontinuity occurs without a change to the timeline. A position
|
||||
@ -287,14 +290,14 @@ public interface Player {
|
||||
* transitioning from one period in the timeline to the next), or when the playback position
|
||||
* jumps within the period currently being played (as a result of a seek being performed, or
|
||||
* when the source introduces a discontinuity internally).
|
||||
* <p>
|
||||
* When a position discontinuity occurs as a result of a change to the timeline this method is
|
||||
* <em>not</em> called. {@link #onTimelineChanged(Timeline, Object, int)} is called in this
|
||||
*
|
||||
* <p>When a position discontinuity occurs as a result of a change to the timeline this method
|
||||
* is <em>not</em> called. {@link #onTimelineChanged(Timeline, Object, int)} is called in this
|
||||
* case.
|
||||
*
|
||||
* @param reason The {@link DiscontinuityReason} responsible for the discontinuity.
|
||||
*/
|
||||
void onPositionDiscontinuity(@DiscontinuityReason int reason);
|
||||
default void onPositionDiscontinuity(@DiscontinuityReason int reason) {}
|
||||
|
||||
/**
|
||||
* Called when the current playback parameters change. The playback parameters may change due to
|
||||
@ -304,20 +307,21 @@ public interface Player {
|
||||
*
|
||||
* @param playbackParameters The playback parameters.
|
||||
*/
|
||||
void onPlaybackParametersChanged(PlaybackParameters playbackParameters);
|
||||
default void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {}
|
||||
|
||||
/**
|
||||
* Called when all pending seek requests have been processed by the player. This is guaranteed
|
||||
* to happen after any necessary changes to the player state were reported to
|
||||
* {@link #onPlayerStateChanged(boolean, int)}.
|
||||
* to happen after any necessary changes to the player state were reported to {@link
|
||||
* #onPlayerStateChanged(boolean, int)}.
|
||||
*/
|
||||
void onSeekProcessed();
|
||||
|
||||
default void onSeekProcessed() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link EventListener} allowing selective overrides. All methods are implemented as no-ops.
|
||||
* @deprecated Use {@link EventListener} interface directly for selective overrides as all methods
|
||||
* are implemented as no-op default methods.
|
||||
*/
|
||||
@Deprecated
|
||||
abstract class DefaultEventListener implements EventListener {
|
||||
|
||||
@Override
|
||||
@ -327,60 +331,11 @@ public interface Player {
|
||||
onTimelineChanged(timeline, manifest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingChanged(boolean isLoading) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRepeatModeChanged(@RepeatMode int repeatMode) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerError(ExoPlaybackException error) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPositionDiscontinuity(@DiscontinuityReason int reason) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSeekProcessed() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link DefaultEventListener#onTimelineChanged(Timeline, Object, int)}
|
||||
* instead.
|
||||
*/
|
||||
/** @deprecated Use {@link EventListener#onTimelineChanged(Timeline, Object, int)} instead. */
|
||||
@Deprecated
|
||||
public void onTimelineChanged(Timeline timeline, Object manifest) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.view.Surface;
|
||||
import com.google.android.exoplayer2.Player.DefaultEventListener;
|
||||
import com.google.android.exoplayer2.Player.EventListener;
|
||||
import com.google.android.exoplayer2.Timeline.Window;
|
||||
import com.google.android.exoplayer2.source.ConcatenatingMediaSource;
|
||||
@ -483,7 +482,7 @@ public final class ExoPlayerTest {
|
||||
.build();
|
||||
final List<Integer> playbackStatesWhenSeekProcessed = new ArrayList<>();
|
||||
EventListener eventListener =
|
||||
new DefaultEventListener() {
|
||||
new EventListener() {
|
||||
private int currentPlaybackState = Player.STATE_IDLE;
|
||||
|
||||
@Override
|
||||
@ -535,7 +534,7 @@ public final class ExoPlayerTest {
|
||||
.build();
|
||||
final boolean[] onSeekProcessedCalled = new boolean[1];
|
||||
EventListener listener =
|
||||
new DefaultEventListener() {
|
||||
new EventListener() {
|
||||
@Override
|
||||
public void onSeekProcessed() {
|
||||
onSeekProcessedCalled[0] = true;
|
||||
@ -1988,7 +1987,7 @@ public final class ExoPlayerTest {
|
||||
final List<Integer> eventListener1States = new ArrayList<>();
|
||||
final List<Integer> eventListener2States = new ArrayList<>();
|
||||
final EventListener eventListener1 =
|
||||
new DefaultEventListener() {
|
||||
new EventListener() {
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
eventListener1States.add(playbackState);
|
||||
@ -1998,7 +1997,7 @@ public final class ExoPlayerTest {
|
||||
}
|
||||
};
|
||||
final EventListener eventListener2 =
|
||||
new DefaultEventListener() {
|
||||
new EventListener() {
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
eventListener2States.add(playbackState);
|
||||
@ -2038,7 +2037,7 @@ public final class ExoPlayerTest {
|
||||
final List<Boolean> eventListenerPlayWhenReady = new ArrayList<>();
|
||||
final List<Integer> eventListenerStates = new ArrayList<>();
|
||||
final EventListener eventListener =
|
||||
new DefaultEventListener() {
|
||||
new EventListener() {
|
||||
@Override
|
||||
public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {
|
||||
if (timeline.isEmpty()) {
|
||||
|
@ -27,7 +27,7 @@ import java.util.Locale;
|
||||
* A helper class for periodically updating a {@link TextView} with debug information obtained from
|
||||
* a {@link SimpleExoPlayer}.
|
||||
*/
|
||||
public class DebugTextViewHelper extends Player.DefaultEventListener implements Runnable {
|
||||
public class DebugTextViewHelper implements Player.EventListener, Runnable {
|
||||
|
||||
private static final int REFRESH_INTERVAL_MS = 1000;
|
||||
|
||||
|
@ -1030,8 +1030,8 @@ public class PlayerControlView extends FrameLayout {
|
||||
return true;
|
||||
}
|
||||
|
||||
private final class ComponentListener extends Player.DefaultEventListener
|
||||
implements TimeBar.OnScrubListener, OnClickListener {
|
||||
private final class ComponentListener
|
||||
implements Player.EventListener, TimeBar.OnScrubListener, OnClickListener {
|
||||
|
||||
@Override
|
||||
public void onScrubStart(TimeBar timeBar, long position) {
|
||||
|
@ -937,7 +937,7 @@ public class PlayerNotificationManager {
|
||||
return actions;
|
||||
}
|
||||
|
||||
private class PlayerListener extends Player.DefaultEventListener {
|
||||
private class PlayerListener implements Player.EventListener {
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
|
@ -1179,8 +1179,8 @@ public class PlayerView extends FrameLayout {
|
||||
|| keyCode == KeyEvent.KEYCODE_DPAD_CENTER;
|
||||
}
|
||||
|
||||
private final class ComponentListener extends Player.DefaultEventListener
|
||||
implements TextOutput, VideoListener, OnLayoutChangeListener {
|
||||
private final class ComponentListener
|
||||
implements Player.EventListener, TextOutput, VideoListener, OnLayoutChangeListener {
|
||||
|
||||
// TextOutput implementation
|
||||
|
||||
|
@ -572,7 +572,7 @@ public abstract class Action {
|
||||
return;
|
||||
}
|
||||
Player.EventListener listener =
|
||||
new Player.DefaultEventListener() {
|
||||
new Player.EventListener() {
|
||||
@Override
|
||||
public void onTimelineChanged(
|
||||
Timeline timeline, Object manifest, @Player.TimelineChangeReason int reason) {
|
||||
@ -618,13 +618,14 @@ public abstract class Action {
|
||||
if (nextAction == null) {
|
||||
return;
|
||||
}
|
||||
player.addListener(new Player.DefaultEventListener() {
|
||||
@Override
|
||||
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
|
||||
player.removeListener(this);
|
||||
nextAction.schedule(player, trackSelector, surface, handler);
|
||||
}
|
||||
});
|
||||
player.addListener(
|
||||
new Player.EventListener() {
|
||||
@Override
|
||||
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
|
||||
player.removeListener(this);
|
||||
nextAction.schedule(player, trackSelector, surface, handler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -663,15 +664,16 @@ public abstract class Action {
|
||||
if (targetPlaybackState == player.getPlaybackState()) {
|
||||
nextAction.schedule(player, trackSelector, surface, handler);
|
||||
} else {
|
||||
player.addListener(new Player.DefaultEventListener() {
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
if (targetPlaybackState == playbackState) {
|
||||
player.removeListener(this);
|
||||
nextAction.schedule(player, trackSelector, surface, handler);
|
||||
}
|
||||
}
|
||||
});
|
||||
player.addListener(
|
||||
new Player.EventListener() {
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
if (targetPlaybackState == playbackState) {
|
||||
player.removeListener(this);
|
||||
nextAction.schedule(player, trackSelector, surface, handler);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -704,13 +706,14 @@ public abstract class Action {
|
||||
if (nextAction == null) {
|
||||
return;
|
||||
}
|
||||
player.addListener(new Player.DefaultEventListener() {
|
||||
@Override
|
||||
public void onSeekProcessed() {
|
||||
player.removeListener(this);
|
||||
nextAction.schedule(player, trackSelector, surface, handler);
|
||||
}
|
||||
});
|
||||
player.addListener(
|
||||
new Player.EventListener() {
|
||||
@Override
|
||||
public void onSeekProcessed() {
|
||||
player.removeListener(this);
|
||||
nextAction.schedule(player, trackSelector, surface, handler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,11 +49,12 @@ import com.google.android.exoplayer2.util.HandlerWrapper;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.google.android.exoplayer2.video.VideoRendererEventListener;
|
||||
|
||||
/**
|
||||
* A {@link HostedTest} for {@link ExoPlayer} playback tests.
|
||||
*/
|
||||
public abstract class ExoHostedTest extends Player.DefaultEventListener implements HostedTest,
|
||||
AudioRendererEventListener, VideoRendererEventListener {
|
||||
/** A {@link HostedTest} for {@link ExoPlayer} playback tests. */
|
||||
public abstract class ExoHostedTest
|
||||
implements Player.EventListener,
|
||||
HostedTest,
|
||||
AudioRendererEventListener,
|
||||
VideoRendererEventListener {
|
||||
|
||||
static {
|
||||
// DefaultAudioSink is able to work around spurious timestamps reported by the platform (by
|
||||
|
@ -51,11 +51,8 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* Helper class to run an ExoPlayer test.
|
||||
*/
|
||||
public final class ExoPlayerTestRunner extends Player.DefaultEventListener
|
||||
implements ActionSchedule.Callback {
|
||||
/** Helper class to run an ExoPlayer test. */
|
||||
public final class ExoPlayerTestRunner implements Player.EventListener, ActionSchedule.Callback {
|
||||
|
||||
/**
|
||||
* Builder to set-up a {@link ExoPlayerTestRunner}. Default fake implementations will be used for
|
||||
|
Loading…
x
Reference in New Issue
Block a user