Change Transformer to use Player.Listener.

AnalyticsListener should not be used for non-analytical actions.

PiperOrigin-RevId: 406355758
This commit is contained in:
samrobinson 2021-10-29 14:35:53 +00:00 committed by tonihei
parent 8e2083a27b
commit 288899ee9d
2 changed files with 16 additions and 19 deletions

View File

@ -45,7 +45,6 @@ import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RenderersFactory; import com.google.android.exoplayer2.RenderersFactory;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.TracksInfo; import com.google.android.exoplayer2.TracksInfo;
import com.google.android.exoplayer2.analytics.AnalyticsListener;
import com.google.android.exoplayer2.audio.AudioRendererEventListener; import com.google.android.exoplayer2.audio.AudioRendererEventListener;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory; import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.mp4.Mp4Extractor; import com.google.android.exoplayer2.extractor.mp4.Mp4Extractor;
@ -573,8 +572,7 @@ public final class TranscodingTransformer {
.setClock(clock) .setClock(clock)
.build(); .build();
player.setMediaItem(mediaItem); player.setMediaItem(mediaItem);
player.addAnalyticsListener( player.addListener(new TranscodingTransformerPlayerListener(mediaItem, muxerWrapper));
new TranscodingTransformerAnalyticsListener(mediaItem, muxerWrapper));
player.prepare(); player.prepare();
progressState = PROGRESS_STATE_WAITING_FOR_AVAILABILITY; progressState = PROGRESS_STATE_WAITING_FOR_AVAILABILITY;
@ -688,30 +686,30 @@ public final class TranscodingTransformer {
} }
} }
private final class TranscodingTransformerAnalyticsListener implements AnalyticsListener { private final class TranscodingTransformerPlayerListener implements Player.Listener {
private final MediaItem mediaItem; private final MediaItem mediaItem;
private final MuxerWrapper muxerWrapper; private final MuxerWrapper muxerWrapper;
public TranscodingTransformerAnalyticsListener(MediaItem mediaItem, MuxerWrapper muxerWrapper) { public TranscodingTransformerPlayerListener(MediaItem mediaItem, MuxerWrapper muxerWrapper) {
this.mediaItem = mediaItem; this.mediaItem = mediaItem;
this.muxerWrapper = muxerWrapper; this.muxerWrapper = muxerWrapper;
} }
@Override @Override
public void onPlaybackStateChanged(EventTime eventTime, int state) { public void onPlaybackStateChanged(int state) {
if (state == Player.STATE_ENDED) { if (state == Player.STATE_ENDED) {
handleTransformationEnded(/* exception= */ null); handleTransformationEnded(/* exception= */ null);
} }
} }
@Override @Override
public void onTimelineChanged(EventTime eventTime, int reason) { public void onTimelineChanged(Timeline timeline, int reason) {
if (progressState != PROGRESS_STATE_WAITING_FOR_AVAILABILITY) { if (progressState != PROGRESS_STATE_WAITING_FOR_AVAILABILITY) {
return; return;
} }
Timeline.Window window = new Timeline.Window(); Timeline.Window window = new Timeline.Window();
eventTime.timeline.getWindow(/* windowIndex= */ 0, window); timeline.getWindow(/* windowIndex= */ 0, window);
if (!window.isPlaceholder) { if (!window.isPlaceholder) {
long durationUs = window.durationUs; long durationUs = window.durationUs;
// Make progress permanently unavailable if the duration is unknown, so that it doesn't jump // Make progress permanently unavailable if the duration is unknown, so that it doesn't jump
@ -726,7 +724,7 @@ public final class TranscodingTransformer {
} }
@Override @Override
public void onTracksInfoChanged(EventTime eventTime, TracksInfo tracksInfo) { public void onTracksInfoChanged(TracksInfo tracksInfo) {
if (muxerWrapper.getTrackCount() == 0) { if (muxerWrapper.getTrackCount() == 0) {
handleTransformationEnded( handleTransformationEnded(
new IllegalStateException( new IllegalStateException(
@ -736,7 +734,7 @@ public final class TranscodingTransformer {
} }
@Override @Override
public void onPlayerError(EventTime eventTime, PlaybackException error) { public void onPlayerError(PlaybackException error) {
handleTransformationEnded(error); handleTransformationEnded(error);
} }

View File

@ -46,7 +46,6 @@ import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RenderersFactory; import com.google.android.exoplayer2.RenderersFactory;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.TracksInfo; import com.google.android.exoplayer2.TracksInfo;
import com.google.android.exoplayer2.analytics.AnalyticsListener;
import com.google.android.exoplayer2.audio.AudioRendererEventListener; import com.google.android.exoplayer2.audio.AudioRendererEventListener;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory; import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.mp4.Mp4Extractor; import com.google.android.exoplayer2.extractor.mp4.Mp4Extractor;
@ -496,7 +495,7 @@ public final class Transformer {
.setClock(clock) .setClock(clock)
.build(); .build();
player.setMediaItem(mediaItem); player.setMediaItem(mediaItem);
player.addAnalyticsListener(new TransformerAnalyticsListener(mediaItem, muxerWrapper)); player.addListener(new TransformerPlayerListener(mediaItem, muxerWrapper));
player.prepare(); player.prepare();
progressState = PROGRESS_STATE_WAITING_FOR_AVAILABILITY; progressState = PROGRESS_STATE_WAITING_FOR_AVAILABILITY;
@ -606,30 +605,30 @@ public final class Transformer {
} }
} }
private final class TransformerAnalyticsListener implements AnalyticsListener { private final class TransformerPlayerListener implements Player.Listener {
private final MediaItem mediaItem; private final MediaItem mediaItem;
private final MuxerWrapper muxerWrapper; private final MuxerWrapper muxerWrapper;
public TransformerAnalyticsListener(MediaItem mediaItem, MuxerWrapper muxerWrapper) { public TransformerPlayerListener(MediaItem mediaItem, MuxerWrapper muxerWrapper) {
this.mediaItem = mediaItem; this.mediaItem = mediaItem;
this.muxerWrapper = muxerWrapper; this.muxerWrapper = muxerWrapper;
} }
@Override @Override
public void onPlaybackStateChanged(EventTime eventTime, int state) { public void onPlaybackStateChanged(int state) {
if (state == Player.STATE_ENDED) { if (state == Player.STATE_ENDED) {
handleTransformationEnded(/* exception= */ null); handleTransformationEnded(/* exception= */ null);
} }
} }
@Override @Override
public void onTimelineChanged(EventTime eventTime, int reason) { public void onTimelineChanged(Timeline timeline, int reason) {
if (progressState != PROGRESS_STATE_WAITING_FOR_AVAILABILITY) { if (progressState != PROGRESS_STATE_WAITING_FOR_AVAILABILITY) {
return; return;
} }
Timeline.Window window = new Timeline.Window(); Timeline.Window window = new Timeline.Window();
eventTime.timeline.getWindow(/* windowIndex= */ 0, window); timeline.getWindow(/* windowIndex= */ 0, window);
if (!window.isPlaceholder) { if (!window.isPlaceholder) {
long durationUs = window.durationUs; long durationUs = window.durationUs;
// Make progress permanently unavailable if the duration is unknown, so that it doesn't jump // Make progress permanently unavailable if the duration is unknown, so that it doesn't jump
@ -644,7 +643,7 @@ public final class Transformer {
} }
@Override @Override
public void onTracksInfoChanged(EventTime eventTime, TracksInfo tracksInfo) { public void onTracksInfoChanged(TracksInfo tracksInfo) {
if (muxerWrapper.getTrackCount() == 0) { if (muxerWrapper.getTrackCount() == 0) {
handleTransformationEnded( handleTransformationEnded(
new IllegalStateException( new IllegalStateException(
@ -654,7 +653,7 @@ public final class Transformer {
} }
@Override @Override
public void onPlayerError(EventTime eventTime, PlaybackException error) { public void onPlayerError(PlaybackException error) {
handleTransformationEnded(error); handleTransformationEnded(error);
} }