Allow to configure custom LivePlaybackSpeedControl in player builders.

Use default implementation otherwise and forward chosen implementation to
internal player.

Issue: #4904
PiperOrigin-RevId: 336840530
This commit is contained in:
christosts 2020-10-13 10:55:44 +01:00 committed by kim-vde
parent 867d27fa72
commit 0756f304d6
5 changed files with 45 additions and 0 deletions

View file

@ -159,6 +159,7 @@ public interface ExoPlayer extends Player {
private SeekParameters seekParameters; private SeekParameters seekParameters;
private boolean pauseAtEndOfMediaItems; private boolean pauseAtEndOfMediaItems;
private long releaseTimeoutMs; private long releaseTimeoutMs;
private LivePlaybackSpeedControl livePlaybackSpeedControl;
private boolean buildCalled; private boolean buildCalled;
private boolean throwWhenStuckBuffering; private boolean throwWhenStuckBuffering;
@ -173,6 +174,7 @@ public interface ExoPlayer extends Player {
* <li>{@link MediaSourceFactory}: {@link DefaultMediaSourceFactory} * <li>{@link MediaSourceFactory}: {@link DefaultMediaSourceFactory}
* <li>{@link LoadControl}: {@link DefaultLoadControl} * <li>{@link LoadControl}: {@link DefaultLoadControl}
* <li>{@link BandwidthMeter}: {@link DefaultBandwidthMeter#getSingletonInstance(Context)} * <li>{@link BandwidthMeter}: {@link DefaultBandwidthMeter#getSingletonInstance(Context)}
* <li>{@link LivePlaybackSpeedControl}: {@link DefaultLivePlaybackSpeedControl}
* <li>{@link Looper}: The {@link Looper} associated with the current thread, or the {@link * <li>{@link Looper}: The {@link Looper} associated with the current thread, or the {@link
* Looper} of the application's main thread if the current thread doesn't have a {@link * Looper} of the application's main thread if the current thread doesn't have a {@link
* Looper} * Looper}
@ -223,6 +225,7 @@ public interface ExoPlayer extends Player {
looper = Util.getCurrentOrMainLooper(); looper = Util.getCurrentOrMainLooper();
useLazyPreparation = true; useLazyPreparation = true;
seekParameters = SeekParameters.DEFAULT; seekParameters = SeekParameters.DEFAULT;
livePlaybackSpeedControl = new DefaultLivePlaybackSpeedControl.Builder().build();
clock = Clock.DEFAULT; clock = Clock.DEFAULT;
throwWhenStuckBuffering = true; throwWhenStuckBuffering = true;
releaseTimeoutMs = DEFAULT_RELEASE_TIMEOUT_MS; releaseTimeoutMs = DEFAULT_RELEASE_TIMEOUT_MS;
@ -385,6 +388,20 @@ public interface ExoPlayer extends Player {
return this; return this;
} }
/**
* Sets the {@link LivePlaybackSpeedControl} that will control the playback speed when playing
* live streams, in order to maintain a steady target offset from the live stream edge.
*
* @param livePlaybackSpeedControl The {@link LivePlaybackSpeedControl}.
* @return This builder.
* @throws IllegalStateException If {@link #build()} has already been called.
*/
public Builder setLivePlaybackSpeedControl(LivePlaybackSpeedControl livePlaybackSpeedControl) {
Assertions.checkState(!buildCalled);
this.livePlaybackSpeedControl = livePlaybackSpeedControl;
return this;
}
/** /**
* Sets the {@link Clock} that will be used by the player. Should only be set for testing * Sets the {@link Clock} that will be used by the player. Should only be set for testing
* purposes. * purposes.
@ -418,6 +435,7 @@ public interface ExoPlayer extends Player {
analyticsCollector, analyticsCollector,
useLazyPreparation, useLazyPreparation,
seekParameters, seekParameters,
livePlaybackSpeedControl,
releaseTimeoutMs, releaseTimeoutMs,
pauseAtEndOfMediaItems, pauseAtEndOfMediaItems,
clock, clock,

View file

@ -256,6 +256,7 @@ public final class ExoPlayerFactory {
/* analyticsCollector= */ null, /* analyticsCollector= */ null,
/* useLazyPreparation= */ true, /* useLazyPreparation= */ true,
SeekParameters.DEFAULT, SeekParameters.DEFAULT,
new DefaultLivePlaybackSpeedControl.Builder().build(),
ExoPlayer.DEFAULT_RELEASE_TIMEOUT_MS, ExoPlayer.DEFAULT_RELEASE_TIMEOUT_MS,
/* pauseAtEndOfMediaItems= */ false, /* pauseAtEndOfMediaItems= */ false,
Clock.DEFAULT, Clock.DEFAULT,

View file

@ -117,6 +117,7 @@ import java.util.concurrent.TimeoutException;
* loads and other initial preparation steps happen immediately. If true, these initial * loads and other initial preparation steps happen immediately. If true, these initial
* preparations are triggered only when the player starts buffering the media. * preparations are triggered only when the player starts buffering the media.
* @param seekParameters The {@link SeekParameters}. * @param seekParameters The {@link SeekParameters}.
* @param livePlaybackSpeedControl The {@link LivePlaybackSpeedControl}.
* @param releaseTimeoutMs The timeout for calls to {@link #release()} in milliseconds. * @param releaseTimeoutMs The timeout for calls to {@link #release()} in milliseconds.
* @param pauseAtEndOfMediaItems Whether to pause playback at the end of each media item. * @param pauseAtEndOfMediaItems Whether to pause playback at the end of each media item.
* @param clock The {@link Clock}. * @param clock The {@link Clock}.
@ -133,6 +134,7 @@ import java.util.concurrent.TimeoutException;
@Nullable AnalyticsCollector analyticsCollector, @Nullable AnalyticsCollector analyticsCollector,
boolean useLazyPreparation, boolean useLazyPreparation,
SeekParameters seekParameters, SeekParameters seekParameters,
LivePlaybackSpeedControl livePlaybackSpeedControl,
long releaseTimeoutMs, long releaseTimeoutMs,
boolean pauseAtEndOfMediaItems, boolean pauseAtEndOfMediaItems,
Clock clock, Clock clock,
@ -182,6 +184,7 @@ import java.util.concurrent.TimeoutException;
shuffleModeEnabled, shuffleModeEnabled,
analyticsCollector, analyticsCollector,
seekParameters, seekParameters,
livePlaybackSpeedControl,
releaseTimeoutMs, releaseTimeoutMs,
pauseAtEndOfMediaItems, pauseAtEndOfMediaItems,
applicationLooper, applicationLooper,

View file

@ -178,6 +178,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
private final PlaybackInfoUpdateListener playbackInfoUpdateListener; private final PlaybackInfoUpdateListener playbackInfoUpdateListener;
private final MediaPeriodQueue queue; private final MediaPeriodQueue queue;
private final MediaSourceList mediaSourceList; private final MediaSourceList mediaSourceList;
private final LivePlaybackSpeedControl livePlaybackSpeedControl;
private final long releaseTimeoutMs; private final long releaseTimeoutMs;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -215,6 +216,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
boolean shuffleModeEnabled, boolean shuffleModeEnabled,
@Nullable AnalyticsCollector analyticsCollector, @Nullable AnalyticsCollector analyticsCollector,
SeekParameters seekParameters, SeekParameters seekParameters,
LivePlaybackSpeedControl livePlaybackSpeedControl,
long releaseTimeoutMs, long releaseTimeoutMs,
boolean pauseAtEndOfWindow, boolean pauseAtEndOfWindow,
Looper applicationLooper, Looper applicationLooper,
@ -229,6 +231,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
this.repeatMode = repeatMode; this.repeatMode = repeatMode;
this.shuffleModeEnabled = shuffleModeEnabled; this.shuffleModeEnabled = shuffleModeEnabled;
this.seekParameters = seekParameters; this.seekParameters = seekParameters;
this.livePlaybackSpeedControl = livePlaybackSpeedControl;
this.releaseTimeoutMs = releaseTimeoutMs; this.releaseTimeoutMs = releaseTimeoutMs;
this.pauseAtEndOfWindow = pauseAtEndOfWindow; this.pauseAtEndOfWindow = pauseAtEndOfWindow;
this.clock = clock; this.clock = clock;

View file

@ -114,6 +114,7 @@ public class SimpleExoPlayer extends BasePlayer
@Renderer.VideoScalingMode private int videoScalingMode; @Renderer.VideoScalingMode private int videoScalingMode;
private boolean useLazyPreparation; private boolean useLazyPreparation;
private SeekParameters seekParameters; private SeekParameters seekParameters;
private LivePlaybackSpeedControl livePlaybackSpeedControl;
private long releaseTimeoutMs; private long releaseTimeoutMs;
private long detachSurfaceTimeoutMs; private long detachSurfaceTimeoutMs;
private boolean pauseAtEndOfMediaItems; private boolean pauseAtEndOfMediaItems;
@ -137,6 +138,7 @@ public class SimpleExoPlayer extends BasePlayer
* <li>{@link MediaSourceFactory}: {@link DefaultMediaSourceFactory} * <li>{@link MediaSourceFactory}: {@link DefaultMediaSourceFactory}
* <li>{@link LoadControl}: {@link DefaultLoadControl} * <li>{@link LoadControl}: {@link DefaultLoadControl}
* <li>{@link BandwidthMeter}: {@link DefaultBandwidthMeter#getSingletonInstance(Context)} * <li>{@link BandwidthMeter}: {@link DefaultBandwidthMeter#getSingletonInstance(Context)}
* <li>{@link LivePlaybackSpeedControl}: {@link DefaultLivePlaybackSpeedControl}
* <li>{@link Looper}: The {@link Looper} associated with the current thread, or the {@link * <li>{@link Looper}: The {@link Looper} associated with the current thread, or the {@link
* Looper} of the application's main thread if the current thread doesn't have a {@link * Looper} of the application's main thread if the current thread doesn't have a {@link
* Looper} * Looper}
@ -246,6 +248,7 @@ public class SimpleExoPlayer extends BasePlayer
videoScalingMode = Renderer.VIDEO_SCALING_MODE_DEFAULT; videoScalingMode = Renderer.VIDEO_SCALING_MODE_DEFAULT;
useLazyPreparation = true; useLazyPreparation = true;
seekParameters = SeekParameters.DEFAULT; seekParameters = SeekParameters.DEFAULT;
livePlaybackSpeedControl = new DefaultLivePlaybackSpeedControl.Builder().build();
clock = Clock.DEFAULT; clock = Clock.DEFAULT;
throwWhenStuckBuffering = true; throwWhenStuckBuffering = true;
releaseTimeoutMs = ExoPlayer.DEFAULT_RELEASE_TIMEOUT_MS; releaseTimeoutMs = ExoPlayer.DEFAULT_RELEASE_TIMEOUT_MS;
@ -518,6 +521,20 @@ public class SimpleExoPlayer extends BasePlayer
return this; return this;
} }
/**
* Sets the {@link LivePlaybackSpeedControl} that will control the playback speed when playing
* live streams, in order to maintain a steady target offset from the live stream edge.
*
* @param livePlaybackSpeedControl The {@link LivePlaybackSpeedControl}.
* @return This builder.
* @throws IllegalStateException If {@link #build()} has already been called.
*/
public Builder setLivePlaybackSpeedControl(LivePlaybackSpeedControl livePlaybackSpeedControl) {
Assertions.checkState(!buildCalled);
this.livePlaybackSpeedControl = livePlaybackSpeedControl;
return this;
}
/** /**
* Sets whether the player should throw when it detects it's stuck buffering. * Sets whether the player should throw when it detects it's stuck buffering.
* *
@ -525,8 +542,10 @@ public class SimpleExoPlayer extends BasePlayer
* *
* @param throwWhenStuckBuffering Whether to throw when the player detects it's stuck buffering. * @param throwWhenStuckBuffering Whether to throw when the player detects it's stuck buffering.
* @return This builder. * @return This builder.
* @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder experimentalSetThrowWhenStuckBuffering(boolean throwWhenStuckBuffering) { public Builder experimentalSetThrowWhenStuckBuffering(boolean throwWhenStuckBuffering) {
Assertions.checkState(!buildCalled);
this.throwWhenStuckBuffering = throwWhenStuckBuffering; this.throwWhenStuckBuffering = throwWhenStuckBuffering;
return this; return this;
} }
@ -677,6 +696,7 @@ public class SimpleExoPlayer extends BasePlayer
analyticsCollector, analyticsCollector,
builder.useLazyPreparation, builder.useLazyPreparation,
builder.seekParameters, builder.seekParameters,
builder.livePlaybackSpeedControl,
builder.releaseTimeoutMs, builder.releaseTimeoutMs,
builder.pauseAtEndOfMediaItems, builder.pauseAtEndOfMediaItems,
builder.clock, builder.clock,