diff --git a/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionEventListener.java b/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionEventListener.java index fa5b60e66e..297f26bb71 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionEventListener.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionEventListener.java @@ -24,7 +24,7 @@ public interface DefaultDrmSessionEventListener { default void onDrmSessionAcquired() {} /** Called each time keys are loaded. */ - void onDrmKeysLoaded(); + default void onDrmKeysLoaded() {} /** * Called when a drm error occurs. @@ -38,13 +38,13 @@ public interface DefaultDrmSessionEventListener { * * @param error The corresponding exception. */ - void onDrmSessionManagerError(Exception error); + default void onDrmSessionManagerError(Exception error) {} /** Called each time offline keys are restored. */ - void onDrmKeysRestored(); + default void onDrmKeysRestored() {} /** Called each time offline keys are removed. */ - void onDrmKeysRemoved(); + default void onDrmKeysRemoved() {} /** Called each time a drm session is released. */ default void onDrmSessionReleased() {} diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceEventListener.java b/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceEventListener.java index 14bafdaf4b..fbb3a86221 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceEventListener.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceEventListener.java @@ -15,78 +15,9 @@ */ package com.google.android.exoplayer2.source; -import androidx.annotation.Nullable; -import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId; -import java.io.IOException; - /** - * A {@link MediaSourceEventListener} allowing selective overrides. All methods are implemented as - * no-ops. + * @deprecated Use {@link MediaSourceEventListener} interface directly for selective overrides as + * all methods are implemented as no-op default methods. */ -public abstract class DefaultMediaSourceEventListener implements MediaSourceEventListener { - - @Override - public void onMediaPeriodCreated(int windowIndex, MediaPeriodId mediaPeriodId) { - // Do nothing. - } - - @Override - public void onMediaPeriodReleased(int windowIndex, MediaPeriodId mediaPeriodId) { - // Do nothing. - } - - @Override - public void onLoadStarted( - int windowIndex, - @Nullable MediaPeriodId mediaPeriodId, - LoadEventInfo loadEventInfo, - MediaLoadData mediaLoadData) { - // Do nothing. - } - - @Override - public void onLoadCompleted( - int windowIndex, - @Nullable MediaPeriodId mediaPeriodId, - LoadEventInfo loadEventInfo, - MediaLoadData mediaLoadData) { - // Do nothing. - } - - @Override - public void onLoadCanceled( - int windowIndex, - @Nullable MediaPeriodId mediaPeriodId, - LoadEventInfo loadEventInfo, - MediaLoadData mediaLoadData) { - // Do nothing. - } - - @Override - public void onLoadError( - int windowIndex, - @Nullable MediaPeriodId mediaPeriodId, - LoadEventInfo loadEventInfo, - MediaLoadData mediaLoadData, - IOException error, - boolean wasCanceled) { - // Do nothing. - } - - @Override - public void onReadingStarted(int windowIndex, MediaPeriodId mediaPeriodId) { - // Do nothing. - } - - @Override - public void onUpstreamDiscarded( - int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) { - // Do nothing. - } - - @Override - public void onDownstreamFormatChanged( - int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) { - // Do nothing. - } -} +@Deprecated +public abstract class DefaultMediaSourceEventListener implements MediaSourceEventListener {} diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaSource.java b/library/core/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaSource.java index ee731cbc09..060027fee7 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaSource.java @@ -365,7 +365,7 @@ public final class ExtractorMediaSource extends CompositeMediaSource { } @Deprecated - private static final class EventListenerWrapper extends DefaultMediaSourceEventListener { + private static final class EventListenerWrapper implements MediaSourceEventListener { private final EventListener eventListener; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/MediaSourceEventListener.java b/library/core/src/main/java/com/google/android/exoplayer2/source/MediaSourceEventListener.java index ab8d86cc55..9e6f4f9cf1 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/MediaSourceEventListener.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/MediaSourceEventListener.java @@ -164,7 +164,7 @@ public interface MediaSourceEventListener { * @param windowIndex The window index in the timeline this media period belongs to. * @param mediaPeriodId The {@link MediaPeriodId} of the created media period. */ - void onMediaPeriodCreated(int windowIndex, MediaPeriodId mediaPeriodId); + default void onMediaPeriodCreated(int windowIndex, MediaPeriodId mediaPeriodId) {} /** * Called when a media period is released by the media source. @@ -172,7 +172,7 @@ public interface MediaSourceEventListener { * @param windowIndex The window index in the timeline this media period belongs to. * @param mediaPeriodId The {@link MediaPeriodId} of the released media period. */ - void onMediaPeriodReleased(int windowIndex, MediaPeriodId mediaPeriodId); + default void onMediaPeriodReleased(int windowIndex, MediaPeriodId mediaPeriodId) {} /** * Called when a load begins. @@ -185,11 +185,11 @@ public interface MediaSourceEventListener { * LoadEventInfo#responseHeaders} will be empty. * @param mediaLoadData The {@link MediaLoadData} defining the data being loaded. */ - void onLoadStarted( + default void onLoadStarted( int windowIndex, @Nullable MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, - MediaLoadData mediaLoadData); + MediaLoadData mediaLoadData) {} /** * Called when a load ends. @@ -203,11 +203,11 @@ public interface MediaSourceEventListener { * event. * @param mediaLoadData The {@link MediaLoadData} defining the data being loaded. */ - void onLoadCompleted( + default void onLoadCompleted( int windowIndex, @Nullable MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, - MediaLoadData mediaLoadData); + MediaLoadData mediaLoadData) {} /** * Called when a load is canceled. @@ -221,11 +221,11 @@ public interface MediaSourceEventListener { * event. * @param mediaLoadData The {@link MediaLoadData} defining the data being loaded. */ - void onLoadCanceled( + default void onLoadCanceled( int windowIndex, @Nullable MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, - MediaLoadData mediaLoadData); + MediaLoadData mediaLoadData) {} /** * Called when a load error occurs. @@ -252,13 +252,13 @@ public interface MediaSourceEventListener { * @param error The load error. * @param wasCanceled Whether the load was canceled as a result of the error. */ - void onLoadError( + default void onLoadError( int windowIndex, @Nullable MediaPeriodId mediaPeriodId, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData, IOException error, - boolean wasCanceled); + boolean wasCanceled) {} /** * Called when a media period is first being read from. @@ -266,7 +266,7 @@ public interface MediaSourceEventListener { * @param windowIndex The window index in the timeline this media period belongs to. * @param mediaPeriodId The {@link MediaPeriodId} of the media period being read from. */ - void onReadingStarted(int windowIndex, MediaPeriodId mediaPeriodId); + default void onReadingStarted(int windowIndex, MediaPeriodId mediaPeriodId) {} /** * Called when data is removed from the back of a media buffer, typically so that it can be @@ -276,8 +276,8 @@ public interface MediaSourceEventListener { * @param mediaPeriodId The {@link MediaPeriodId} the media belongs to. * @param mediaLoadData The {@link MediaLoadData} defining the media being discarded. */ - void onUpstreamDiscarded( - int windowIndex, MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData); + default void onUpstreamDiscarded( + int windowIndex, MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {} /** * Called when a downstream format change occurs (i.e. when the format of the media being read @@ -287,8 +287,8 @@ public interface MediaSourceEventListener { * @param mediaPeriodId The {@link MediaPeriodId} the media belongs to. * @param mediaLoadData The {@link MediaLoadData} defining the newly selected downstream data. */ - void onDownstreamFormatChanged( - int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData); + default void onDownstreamFormatChanged( + int windowIndex, @Nullable MediaPeriodId mediaPeriodId, MediaLoadData mediaLoadData) {} /** Dispatches events to {@link MediaSourceEventListener}s. */ final class EventDispatcher { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaSource.java b/library/core/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaSource.java index be939fd018..db1414942f 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaSource.java @@ -347,7 +347,7 @@ public final class SingleSampleMediaSource extends BaseMediaSource { */ @Deprecated @SuppressWarnings("deprecation") - private static final class EventListenerWrapper extends DefaultMediaSourceEventListener { + private static final class EventListenerWrapper implements MediaSourceEventListener { private final EventListener eventListener; private final int eventSourceId; diff --git a/library/core/src/test/java/com/google/android/exoplayer2/source/ClippingMediaSourceTest.java b/library/core/src/test/java/com/google/android/exoplayer2/source/ClippingMediaSourceTest.java index 532ad61b85..b2dc666790 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/source/ClippingMediaSourceTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/source/ClippingMediaSourceTest.java @@ -555,7 +555,7 @@ public final class ClippingMediaSourceTest { () -> clippingMediaSource.addEventListener( new Handler(), - new DefaultMediaSourceEventListener() { + new MediaSourceEventListener() { @Override public void onDownstreamFormatChanged( int windowIndex,