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 new file mode 100644 index 0000000000..044ab87e6a --- /dev/null +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceEventListener.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.android.exoplayer2.source; + +import java.io.IOException; + +/** + * A {@link MediaSourceEventListener} allowing selective overrides. All methods are implemented as + * no-ops. + */ +public abstract class DefaultMediaSourceEventListener implements MediaSourceEventListener { + + @Override + public void onLoadStarted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { + // Do nothing. + } + + @Override + public void onLoadCompleted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { + // Do nothing. + } + + @Override + public void onLoadCanceled(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { + // Do nothing. + } + + @Override + public void onLoadError( + LoadEventInfo loadEventInfo, + MediaLoadData mediaLoadData, + IOException error, + boolean wasCanceled) { + // Do nothing. + } + + @Override + public void onUpstreamDiscarded(MediaLoadData mediaLoadData) { + // Do nothing. + } + + @Override + public void onDownstreamFormatChanged(MediaLoadData mediaLoadData) { + // Do nothing. + } +} 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 20ef5ab147..20e789821d 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 @@ -20,7 +20,6 @@ import android.os.Handler; import android.support.annotation.Nullable; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.ExoPlayer; -import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory; import com.google.android.exoplayer2.extractor.Extractor; @@ -29,7 +28,6 @@ import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispat import com.google.android.exoplayer2.source.ads.AdsMediaSource; import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.DataSource; -import com.google.android.exoplayer2.upstream.DataSpec; import com.google.android.exoplayer2.util.Assertions; import java.io.IOException; @@ -386,90 +384,20 @@ public final class ExtractorMediaSource extends BaseMediaSource * Wraps a deprecated {@link EventListener}, invoking its callback from the equivalent callback in * {@link MediaSourceEventListener}. */ - private static final class EventListenerWrapper implements MediaSourceEventListener { + private static final class EventListenerWrapper extends DefaultMediaSourceEventListener { private final EventListener eventListener; public EventListenerWrapper(EventListener eventListener) { this.eventListener = Assertions.checkNotNull(eventListener); } - @Override - public void onLoadStarted( - DataSpec dataSpec, - int dataType, - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaStartTimeMs, - long mediaEndTimeMs, - long elapsedRealtimeMs) { - // Do nothing. - } - - @Override - public void onLoadCompleted( - DataSpec dataSpec, - int dataType, - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaStartTimeMs, - long mediaEndTimeMs, - long elapsedRealtimeMs, - long loadDurationMs, - long bytesLoaded) { - // Do nothing. - } - - @Override - public void onLoadCanceled( - DataSpec dataSpec, - int dataType, - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaStartTimeMs, - long mediaEndTimeMs, - long elapsedRealtimeMs, - long loadDurationMs, - long bytesLoaded) { - // Do nothing. - } - @Override public void onLoadError( - DataSpec dataSpec, - int dataType, - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaStartTimeMs, - long mediaEndTimeMs, - long elapsedRealtimeMs, - long loadDurationMs, - long bytesLoaded, + LoadEventInfo loadEventInfo, + MediaLoadData mediaLoadData, IOException error, boolean wasCanceled) { eventListener.onLoadError(error); } - - @Override - public void onUpstreamDiscarded(int trackType, long mediaStartTimeMs, long mediaEndTimeMs) { - // Do nothing. - } - - @Override - public void onDownstreamFormatChanged( - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaTimeMs) { - // Do nothing. - } } } 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 9fc2572b55..9bea5a23e3 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 @@ -27,107 +27,127 @@ import java.io.IOException; /** Interface for callbacks to be notified of {@link MediaSource} events. */ public interface MediaSourceEventListener { + + /** Media source load event information. */ + final class LoadEventInfo { + + /** Defines the data being loaded. */ + public final DataSpec dataSpec; + /** The value of {@link SystemClock#elapsedRealtime} at the time of the load event. */ + public final long elapsedRealtimeMs; + /** The duration of the load up to the event time. */ + public final long loadDurationMs; + /** The number of bytes that were loaded up to the event time. */ + public final long bytesLoaded; + + /** + * Creates load event info. + * + * @param dataSpec Defines the data being loaded. + * @param elapsedRealtimeMs The value of {@link SystemClock#elapsedRealtime} at the time of the + * load event. + * @param loadDurationMs The duration of the load up to the event time. + * @param bytesLoaded The number of bytes that were loaded up to the event time. + */ + public LoadEventInfo( + DataSpec dataSpec, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) { + this.dataSpec = dataSpec; + this.elapsedRealtimeMs = elapsedRealtimeMs; + this.loadDurationMs = loadDurationMs; + this.bytesLoaded = bytesLoaded; + } + } + + /** Descriptor for data being loaded or selected by a media source. */ + final class MediaLoadData { + /** One of the {@link C} {@code DATA_TYPE_*} constants defining the type of data. */ + public final int dataType; + /** + * One of the {@link C} {@code TRACK_TYPE_*} constants if the data corresponds to media of a + * specific type. {@link C#TRACK_TYPE_UNKNOWN} otherwise. + */ + public final int trackType; + /** + * The format of the track to which the data belongs. Null if the data does not belong to a + * specific track. + */ + public final @Nullable Format trackFormat; + /** + * One of the {@link C} {@code SELECTION_REASON_*} constants if the data belongs to a track. + * {@link C#SELECTION_REASON_UNKNOWN} otherwise. + */ + public final int trackSelectionReason; + /** + * Optional data associated with the selection of the track to which the data belongs. Null if + * the data does not belong to a track. + */ + public final @Nullable Object trackSelectionData; + /** The start time of the media, or {@link C#TIME_UNSET} if the data is not for media. */ + public final long mediaStartTimeMs; + /** + * The end time of the media, or {@link C#TIME_UNSET} if the data is not for media or the end + * time is unknown. + */ + public final long mediaEndTimeMs; + + /** + * Creates media load data. + * + * @param dataType One of the {@link C} {@code DATA_TYPE_*} constants defining the type of data. + * @param trackType One of the {@link C} {@code TRACK_TYPE_*} constants if the data corresponds + * to media of a specific type. {@link C#TRACK_TYPE_UNKNOWN} otherwise. + * @param trackFormat The format of the track to which the data belongs. Null if the data does + * not belong to a track. + * @param trackSelectionReason One of the {@link C} {@code SELECTION_REASON_*} constants if the + * data belongs to a track. {@link C#SELECTION_REASON_UNKNOWN} otherwise. + * @param trackSelectionData Optional data associated with the selection of the track to which + * the data belongs. Null if the data does not belong to a track. + * @param mediaStartTimeMs The start time of the media, or {@link C#TIME_UNSET} if the data is + * not for media. + * @param mediaEndTimeMs The end time of the media, or {@link C#TIME_UNSET} if the data is not + * for media or the end time is unknown. + */ + public MediaLoadData( + int dataType, + int trackType, + @Nullable Format trackFormat, + int trackSelectionReason, + @Nullable Object trackSelectionData, + long mediaStartTimeMs, + long mediaEndTimeMs) { + this.dataType = dataType; + this.trackType = trackType; + this.trackFormat = trackFormat; + this.trackSelectionReason = trackSelectionReason; + this.trackSelectionData = trackSelectionData; + this.mediaStartTimeMs = mediaStartTimeMs; + this.mediaEndTimeMs = mediaEndTimeMs; + } + } + /** * Called when a load begins. * - * @param dataSpec Defines the data being loaded. - * @param dataType One of the {@link C} {@code DATA_TYPE_*} constants defining the type of data - * being loaded. - * @param trackType One of the {@link C} {@code TRACK_TYPE_*} constants if the data corresponds to - * media of a specific type. {@link C#TRACK_TYPE_UNKNOWN} otherwise. - * @param trackFormat The format of the track to which the data belongs. Null if the data does not - * belong to a track. - * @param trackSelectionReason One of the {@link C} {@code SELECTION_REASON_*} constants if the - * data belongs to a track. {@link C#SELECTION_REASON_UNKNOWN} otherwise. - * @param trackSelectionData Optional data associated with the selection of the track to which the - * data belongs. Null if the data does not belong to a track. - * @param mediaStartTimeMs The start time of the media being loaded, or {@link C#TIME_UNSET} if - * the load is not for media data. - * @param mediaEndTimeMs The end time of the media being loaded, or {@link C#TIME_UNSET} if the - * load is not for media data or the end time is unknown. - * @param elapsedRealtimeMs The value of {@link SystemClock#elapsedRealtime} when the load began. + * @param loadEventInfo The {@link LoadEventInfo} defining the load event. + * @param mediaLoadData The {@link MediaLoadData} defining the data being loaded. */ - void onLoadStarted( - DataSpec dataSpec, - int dataType, - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaStartTimeMs, - long mediaEndTimeMs, - long elapsedRealtimeMs); + void onLoadStarted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData); /** * Called when a load ends. * - * @param dataSpec Defines the data being loaded. - * @param dataType One of the {@link C} {@code DATA_TYPE_*} constants defining the type of data - * being loaded. - * @param trackType One of the {@link C} {@code TRACK_TYPE_*} constants if the data corresponds to - * media of a specific type. {@link C#TRACK_TYPE_UNKNOWN} otherwise. - * @param trackFormat The format of the track to which the data belongs. Null if the data does not - * belong to a track. - * @param trackSelectionReason One of the {@link C} {@code SELECTION_REASON_*} constants if the - * data belongs to a track. {@link C#SELECTION_REASON_UNKNOWN} otherwise. - * @param trackSelectionData Optional data associated with the selection of the track to which the - * data belongs. Null if the data does not belong to a track. - * @param mediaStartTimeMs The start time of the media being loaded, or {@link C#TIME_UNSET} if - * the load is not for media data. - * @param mediaEndTimeMs The end time of the media being loaded, or {@link C#TIME_UNSET} if the - * load is not for media data. - * @param elapsedRealtimeMs The value of {@link SystemClock#elapsedRealtime} when the load ended. - * @param loadDurationMs The duration of the load. - * @param bytesLoaded The number of bytes that were loaded. + * @param loadEventInfo The {@link LoadEventInfo} defining the load event. + * @param mediaLoadData The {@link MediaLoadData} defining the data being loaded. */ - void onLoadCompleted( - DataSpec dataSpec, - int dataType, - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaStartTimeMs, - long mediaEndTimeMs, - long elapsedRealtimeMs, - long loadDurationMs, - long bytesLoaded); + void onLoadCompleted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData); /** * Called when a load is canceled. * - * @param dataSpec Defines the data being loaded. - * @param dataType One of the {@link C} {@code DATA_TYPE_*} constants defining the type of data - * being loaded. - * @param trackType One of the {@link C} {@code TRACK_TYPE_*} constants if the data corresponds to - * media of a specific type. {@link C#TRACK_TYPE_UNKNOWN} otherwise. - * @param trackFormat The format of the track to which the data belongs. Null if the data does not - * belong to a track. - * @param trackSelectionReason One of the {@link C} {@code SELECTION_REASON_*} constants if the - * data belongs to a track. {@link C#SELECTION_REASON_UNKNOWN} otherwise. - * @param trackSelectionData Optional data associated with the selection of the track to which the - * data belongs. Null if the data does not belong to a track. - * @param mediaStartTimeMs The start time of the media being loaded, or {@link C#TIME_UNSET} if - * the load is not for media data. - * @param mediaEndTimeMs The end time of the media being loaded, or {@link C#TIME_UNSET} if the - * load is not for media data. - * @param elapsedRealtimeMs The value of {@link SystemClock#elapsedRealtime} when the load was - * canceled. - * @param loadDurationMs The duration of the load up to the point at which it was canceled. - * @param bytesLoaded The number of bytes that were loaded prior to cancelation. + * @param loadEventInfo The {@link LoadEventInfo} defining the load event. + * @param mediaLoadData The {@link MediaLoadData} defining the data being loaded. */ - void onLoadCanceled( - DataSpec dataSpec, - int dataType, - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaStartTimeMs, - long mediaEndTimeMs, - long elapsedRealtimeMs, - long loadDurationMs, - long bytesLoaded); + void onLoadCanceled(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData); /** * Called when a load error occurs. @@ -143,40 +163,14 @@ public interface MediaSourceEventListener { * such behavior). This method is called to provide the application with an opportunity to log the * error if it wishes to do so. * - * @param dataSpec Defines the data being loaded. - * @param dataType One of the {@link C} {@code DATA_TYPE_*} constants defining the type of data - * being loaded. - * @param trackType One of the {@link C} {@code TRACK_TYPE_*} constants if the data corresponds to - * media of a specific type. {@link C#TRACK_TYPE_UNKNOWN} otherwise. - * @param trackFormat The format of the track to which the data belongs. Null if the data does not - * belong to a track. - * @param trackSelectionReason One of the {@link C} {@code SELECTION_REASON_*} constants if the - * data belongs to a track. {@link C#SELECTION_REASON_UNKNOWN} otherwise. - * @param trackSelectionData Optional data associated with the selection of the track to which the - * data belongs. Null if the data does not belong to a track. - * @param mediaStartTimeMs The start time of the media being loaded, or {@link C#TIME_UNSET} if - * the load is not for media data. - * @param mediaEndTimeMs The end time of the media being loaded, or {@link C#TIME_UNSET} if the - * load is not for media data. - * @param elapsedRealtimeMs The value of {@link SystemClock#elapsedRealtime} when the error - * occurred. - * @param loadDurationMs The duration of the load up to the point at which the error occurred. - * @param bytesLoaded The number of bytes that were loaded prior to the error. + * @param loadEventInfo The {@link LoadEventInfo} defining the load event. + * @param mediaLoadData The {@link MediaLoadData} defining the data being loaded. * @param error The load error. * @param wasCanceled Whether the load was canceled as a result of the error. */ void onLoadError( - DataSpec dataSpec, - int dataType, - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaStartTimeMs, - long mediaEndTimeMs, - long elapsedRealtimeMs, - long loadDurationMs, - long bytesLoaded, + LoadEventInfo loadEventInfo, + MediaLoadData mediaLoadData, IOException error, boolean wasCanceled); @@ -184,31 +178,17 @@ public interface MediaSourceEventListener { * Called when data is removed from the back of a media buffer, typically so that it can be * re-buffered in a different format. * - * @param trackType The type of the media. One of the {@link C} {@code TRACK_TYPE_*} constants. - * @param mediaStartTimeMs The start time of the media being discarded. - * @param mediaEndTimeMs The end time of the media being discarded. + * @param mediaLoadData The {@link MediaLoadData} defining the media being discarded. */ - void onUpstreamDiscarded(int trackType, long mediaStartTimeMs, long mediaEndTimeMs); + void onUpstreamDiscarded(MediaLoadData mediaLoadData); /** * Called when a downstream format change occurs (i.e. when the format of the media being read * from one or more {@link SampleStream}s provided by the source changes). * - * @param trackType The type of the media. One of the {@link C} {@code TRACK_TYPE_*} constants. - * @param trackFormat The format of the track to which the data belongs. Null if the data does not - * belong to a track. - * @param trackSelectionReason One of the {@link C} {@code SELECTION_REASON_*} constants if the - * data belongs to a track. {@link C#SELECTION_REASON_UNKNOWN} otherwise. - * @param trackSelectionData Optional data associated with the selection of the track to which the - * data belongs. Null if the data does not belong to a track. - * @param mediaTimeMs The media time at which the change occurred. + * @param mediaLoadData The {@link MediaLoadData} defining the newly selected downstream data. */ - void onDownstreamFormatChanged( - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaTimeMs); + void onDownstreamFormatChanged(MediaLoadData mediaLoadData); /** Dispatches events to a {@link MediaSourceEventListener}. */ final class EventDispatcher { @@ -247,13 +227,14 @@ public interface MediaSourceEventListener { elapsedRealtimeMs); } + /** Dispatches {@link #onLoadStarted(LoadEventInfo, MediaLoadData)}. */ public void loadStarted( final DataSpec dataSpec, final int dataType, final int trackType, - final Format trackFormat, + final @Nullable Format trackFormat, final int trackSelectionReason, - final Object trackSelectionData, + final @Nullable Object trackSelectionData, final long mediaStartTimeUs, final long mediaEndTimeUs, final long elapsedRealtimeMs) { @@ -263,20 +244,22 @@ public interface MediaSourceEventListener { @Override public void run() { listener.onLoadStarted( - dataSpec, - dataType, - trackType, - trackFormat, - trackSelectionReason, - trackSelectionData, - adjustMediaTime(mediaStartTimeUs), - adjustMediaTime(mediaEndTimeUs), - elapsedRealtimeMs); + new LoadEventInfo( + dataSpec, elapsedRealtimeMs, /* loadDurationMs= */ 0, /* bytesLoaded= */ 0), + new MediaLoadData( + dataType, + trackType, + trackFormat, + trackSelectionReason, + trackSelectionData, + adjustMediaTime(mediaStartTimeUs), + adjustMediaTime(mediaEndTimeUs))); } }); } } + /** Dispatches {@link #onLoadCompleted(LoadEventInfo, MediaLoadData)}. */ public void loadCompleted( DataSpec dataSpec, int dataType, @@ -297,13 +280,14 @@ public interface MediaSourceEventListener { bytesLoaded); } + /** Dispatches {@link #onLoadCompleted(LoadEventInfo, MediaLoadData)}. */ public void loadCompleted( final DataSpec dataSpec, final int dataType, final int trackType, - final Format trackFormat, + final @Nullable Format trackFormat, final int trackSelectionReason, - final Object trackSelectionData, + final @Nullable Object trackSelectionData, final long mediaStartTimeUs, final long mediaEndTimeUs, final long elapsedRealtimeMs, @@ -315,22 +299,21 @@ public interface MediaSourceEventListener { @Override public void run() { listener.onLoadCompleted( - dataSpec, - dataType, - trackType, - trackFormat, - trackSelectionReason, - trackSelectionData, - adjustMediaTime(mediaStartTimeUs), - adjustMediaTime(mediaEndTimeUs), - elapsedRealtimeMs, - loadDurationMs, - bytesLoaded); + new LoadEventInfo(dataSpec, elapsedRealtimeMs, loadDurationMs, bytesLoaded), + new MediaLoadData( + dataType, + trackType, + trackFormat, + trackSelectionReason, + trackSelectionData, + adjustMediaTime(mediaStartTimeUs), + adjustMediaTime(mediaEndTimeUs))); } }); } } + /** Dispatches {@link #onLoadCanceled(LoadEventInfo, MediaLoadData)}. */ public void loadCanceled( DataSpec dataSpec, int dataType, @@ -351,13 +334,14 @@ public interface MediaSourceEventListener { bytesLoaded); } + /** Dispatches {@link #onLoadCanceled(LoadEventInfo, MediaLoadData)}. */ public void loadCanceled( final DataSpec dataSpec, final int dataType, final int trackType, - final Format trackFormat, + final @Nullable Format trackFormat, final int trackSelectionReason, - final Object trackSelectionData, + final @Nullable Object trackSelectionData, final long mediaStartTimeUs, final long mediaEndTimeUs, final long elapsedRealtimeMs, @@ -369,22 +353,21 @@ public interface MediaSourceEventListener { @Override public void run() { listener.onLoadCanceled( - dataSpec, - dataType, - trackType, - trackFormat, - trackSelectionReason, - trackSelectionData, - adjustMediaTime(mediaStartTimeUs), - adjustMediaTime(mediaEndTimeUs), - elapsedRealtimeMs, - loadDurationMs, - bytesLoaded); + new LoadEventInfo(dataSpec, elapsedRealtimeMs, loadDurationMs, bytesLoaded), + new MediaLoadData( + dataType, + trackType, + trackFormat, + trackSelectionReason, + trackSelectionData, + adjustMediaTime(mediaStartTimeUs), + adjustMediaTime(mediaEndTimeUs))); } }); } } + /** Dispatches {@link #onLoadError(LoadEventInfo, MediaLoadData, IOException, boolean)}. */ public void loadError( DataSpec dataSpec, int dataType, @@ -409,13 +392,14 @@ public interface MediaSourceEventListener { wasCanceled); } + /** Dispatches {@link #onLoadError(LoadEventInfo, MediaLoadData, IOException, boolean)}. */ public void loadError( final DataSpec dataSpec, final int dataType, final int trackType, - final Format trackFormat, + final @Nullable Format trackFormat, final int trackSelectionReason, - final Object trackSelectionData, + final @Nullable Object trackSelectionData, final long mediaStartTimeUs, final long mediaEndTimeUs, final long elapsedRealtimeMs, @@ -429,17 +413,15 @@ public interface MediaSourceEventListener { @Override public void run() { listener.onLoadError( - dataSpec, - dataType, - trackType, - trackFormat, - trackSelectionReason, - trackSelectionData, - adjustMediaTime(mediaStartTimeUs), - adjustMediaTime(mediaEndTimeUs), - elapsedRealtimeMs, - loadDurationMs, - bytesLoaded, + new LoadEventInfo(dataSpec, elapsedRealtimeMs, loadDurationMs, bytesLoaded), + new MediaLoadData( + dataType, + trackType, + trackFormat, + trackSelectionReason, + trackSelectionData, + adjustMediaTime(mediaStartTimeUs), + adjustMediaTime(mediaEndTimeUs)), error, wasCanceled); } @@ -447,6 +429,7 @@ public interface MediaSourceEventListener { } } + /** Dispatches {@link #onUpstreamDiscarded(MediaLoadData)}. */ public void upstreamDiscarded( final int trackType, final long mediaStartTimeUs, final long mediaEndTimeUs) { if (listener != null && handler != null) { @@ -455,17 +438,25 @@ public interface MediaSourceEventListener { @Override public void run() { listener.onUpstreamDiscarded( - trackType, adjustMediaTime(mediaStartTimeUs), adjustMediaTime(mediaEndTimeUs)); + new MediaLoadData( + C.DATA_TYPE_MEDIA, + trackType, + /* trackFormat= */ null, + C.SELECTION_REASON_ADAPTIVE, + /* trackSelectionData= */ null, + adjustMediaTime(mediaStartTimeUs), + adjustMediaTime(mediaEndTimeUs))); } }); } } + /** Dispatches {@link #onDownstreamFormatChanged(MediaLoadData)}. */ public void downstreamFormatChanged( final int trackType, - final Format trackFormat, + final @Nullable Format trackFormat, final int trackSelectionReason, - final Object trackSelectionData, + final @Nullable Object trackSelectionData, final long mediaTimeUs) { if (listener != null && handler != null) { handler.post( @@ -473,11 +464,14 @@ public interface MediaSourceEventListener { @Override public void run() { listener.onDownstreamFormatChanged( - trackType, - trackFormat, - trackSelectionReason, - trackSelectionData, - adjustMediaTime(mediaTimeUs)); + new MediaLoadData( + C.DATA_TYPE_MEDIA, + trackType, + trackFormat, + trackSelectionReason, + trackSelectionData, + adjustMediaTime(mediaTimeUs), + /* mediaEndTimeMs= */ C.TIME_UNSET)); } }); } 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 445f0b882e..fa1389f538 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 @@ -286,7 +286,7 @@ public final class SingleSampleMediaSource extends BaseMediaSource { * Wraps a deprecated {@link EventListener}, invoking its callback from the equivalent callback in * {@link MediaSourceEventListener}. */ - private static final class EventListenerWrapper implements MediaSourceEventListener { + private static final class EventListenerWrapper extends DefaultMediaSourceEventListener { private final EventListener eventListener; private final int eventSourceId; @@ -296,83 +296,13 @@ public final class SingleSampleMediaSource extends BaseMediaSource { this.eventSourceId = eventSourceId; } - @Override - public void onLoadStarted( - DataSpec dataSpec, - int dataType, - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaStartTimeMs, - long mediaEndTimeMs, - long elapsedRealtimeMs) { - // Do nothing. - } - - @Override - public void onLoadCompleted( - DataSpec dataSpec, - int dataType, - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaStartTimeMs, - long mediaEndTimeMs, - long elapsedRealtimeMs, - long loadDurationMs, - long bytesLoaded) { - // Do nothing. - } - - @Override - public void onLoadCanceled( - DataSpec dataSpec, - int dataType, - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaStartTimeMs, - long mediaEndTimeMs, - long elapsedRealtimeMs, - long loadDurationMs, - long bytesLoaded) { - // Do nothing. - } - @Override public void onLoadError( - DataSpec dataSpec, - int dataType, - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaStartTimeMs, - long mediaEndTimeMs, - long elapsedRealtimeMs, - long loadDurationMs, - long bytesLoaded, + LoadEventInfo loadEventInfo, + MediaLoadData mediaLoadData, IOException error, boolean wasCanceled) { eventListener.onLoadError(eventSourceId, error); } - - @Override - public void onUpstreamDiscarded(int trackType, long mediaStartTimeMs, long mediaEndTimeMs) { - // Do nothing. - } - - @Override - public void onDownstreamFormatChanged( - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaTimeMs) { - // Do nothing. - } } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/EventLogger.java b/library/core/src/main/java/com/google/android/exoplayer2/util/EventLogger.java index df555b824a..dbe5b0b6a7 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/util/EventLogger.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/EventLogger.java @@ -47,7 +47,6 @@ import com.google.android.exoplayer2.trackselection.MappingTrackSelector; import com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo; import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelectionArray; -import com.google.android.exoplayer2.upstream.DataSpec; import com.google.android.exoplayer2.video.VideoRendererEventListener; import java.io.IOException; import java.text.NumberFormat; @@ -362,49 +361,36 @@ public class EventLogger // MediaSourceEventListener @Override - public void onLoadStarted( - DataSpec dataSpec, - int dataType, - int trackType, - Format trackFormat, - int trackSelectionReason, - Object trackSelectionData, - long mediaStartTimeMs, - long mediaEndTimeMs, - long elapsedRealtimeMs) { + public void onLoadStarted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { // Do nothing. } @Override - public void onLoadError(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, - int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, - long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded, - IOException error, boolean wasCanceled) { + public void onLoadError( + LoadEventInfo loadEventInfo, + MediaLoadData mediaLoadData, + IOException error, + boolean wasCanceled) { printInternalError("loadError", error); } @Override - public void onLoadCanceled(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, - int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, - long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) { + public void onLoadCanceled(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { // Do nothing. } @Override - public void onLoadCompleted(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, - int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, - long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) { + public void onLoadCompleted(LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) { // Do nothing. } @Override - public void onUpstreamDiscarded(int trackType, long mediaStartTimeMs, long mediaEndTimeMs) { + public void onUpstreamDiscarded(MediaLoadData mediaLoadData) { // Do nothing. } @Override - public void onDownstreamFormatChanged(int trackType, Format trackFormat, int trackSelectionReason, - Object trackSelectionData, long mediaTimeMs) { + public void onDownstreamFormatChanged(MediaLoadData mediaLoadData) { // Do nothing. }