From d5710d3171125b01bef4538a08c3e6c918c145fd Mon Sep 17 00:00:00 2001 From: tonihei Date: Tue, 16 Aug 2022 16:27:56 +0000 Subject: [PATCH] Define CueGroup.EMPTY_TIME_ZERO for convenience We create an empty CueGroup in many places as default or where none is needed. Instead, we can define a constant for this purpose and reuse it. PiperOrigin-RevId: 467944841 (cherry picked from commit 29208ec1ed4d78fa86af33b81a2b32f3151b9004) --- .../com/google/android/exoplayer2/ext/cast/CastPlayer.java | 4 +--- .../java/com/google/android/exoplayer2/text/CueGroup.java | 5 +++++ .../java/com/google/android/exoplayer2/ExoPlayerImpl.java | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java b/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java index afe0312c28..252ab7251d 100644 --- a/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java +++ b/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java @@ -111,8 +111,6 @@ public final class CastPlayer extends BasePlayer { private static final long PROGRESS_REPORT_PERIOD_MS = 1000; private static final long[] EMPTY_TRACK_ID_ARRAY = new long[0]; - private static final CueGroup EMPTY_CUE_GROUP = - new CueGroup(ImmutableList.of(), /* presentationTimeUs= */ 0); private final CastContext castContext; private final MediaItemConverter mediaItemConverter; @@ -726,7 +724,7 @@ public final class CastPlayer extends BasePlayer { /** This method is not supported and returns an empty {@link CueGroup}. */ @Override public CueGroup getCurrentCues() { - return EMPTY_CUE_GROUP; + return CueGroup.EMPTY_TIME_ZERO; } /** This method is not supported and always returns {@link DeviceInfo#UNKNOWN}. */ diff --git a/library/common/src/main/java/com/google/android/exoplayer2/text/CueGroup.java b/library/common/src/main/java/com/google/android/exoplayer2/text/CueGroup.java index 93d260e673..a45d55aff3 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/text/CueGroup.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/text/CueGroup.java @@ -34,6 +34,11 @@ import java.util.List; /** Class to represent the state of active {@link Cue Cues} at a particular time. */ public final class CueGroup implements Bundleable { + + /** An empty group with no {@link Cue Cues} and presentation time of zero. */ + public static final CueGroup EMPTY_TIME_ZERO = + new CueGroup(ImmutableList.of(), /* presentationTimeUs= */ 0); + /** * The cues in this group. * diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java index bfda921a0b..8709003c01 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java @@ -345,7 +345,7 @@ import java.util.concurrent.TimeoutException; } else { audioSessionId = Util.generateAudioSessionIdV21(applicationContext); } - currentCueGroup = new CueGroup(ImmutableList.of(), /* presentationTimeUs= */ 0); + currentCueGroup = CueGroup.EMPTY_TIME_ZERO; throwsWhenUsingWrongThread = true; addListener(analyticsCollector); @@ -990,7 +990,7 @@ import java.util.concurrent.TimeoutException; checkNotNull(priorityTaskManager).remove(C.PRIORITY_PLAYBACK); isPriorityTaskManagerRegistered = false; } - currentCueGroup = new CueGroup(ImmutableList.of(), /* presentationTimeUs= */ 0); + currentCueGroup = CueGroup.EMPTY_TIME_ZERO; playerReleased = true; }