Commit 0756f304 by christosts Committed by kim-vde

Allow to configure custom LivePlaybackSpeedControl in player builders.

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

Issue: #4904
PiperOrigin-RevId: 336840530
parent 867d27fa
......@@ -159,6 +159,7 @@ public interface ExoPlayer extends Player {
private SeekParameters seekParameters;
private boolean pauseAtEndOfMediaItems;
private long releaseTimeoutMs;
private LivePlaybackSpeedControl livePlaybackSpeedControl;
private boolean buildCalled;
private boolean throwWhenStuckBuffering;
......@@ -173,6 +174,7 @@ public interface ExoPlayer extends Player {
* <li>{@link MediaSourceFactory}: {@link DefaultMediaSourceFactory}
* <li>{@link LoadControl}: {@link DefaultLoadControl}
* <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
* Looper} of the application's main thread if the current thread doesn't have a {@link
* Looper}
......@@ -223,6 +225,7 @@ public interface ExoPlayer extends Player {
looper = Util.getCurrentOrMainLooper();
useLazyPreparation = true;
seekParameters = SeekParameters.DEFAULT;
livePlaybackSpeedControl = new DefaultLivePlaybackSpeedControl.Builder().build();
clock = Clock.DEFAULT;
throwWhenStuckBuffering = true;
releaseTimeoutMs = DEFAULT_RELEASE_TIMEOUT_MS;
......@@ -386,6 +389,20 @@ public interface ExoPlayer extends Player {
}
/**
* 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
* purposes.
*
......@@ -418,6 +435,7 @@ public interface ExoPlayer extends Player {
analyticsCollector,
useLazyPreparation,
seekParameters,
livePlaybackSpeedControl,
releaseTimeoutMs,
pauseAtEndOfMediaItems,
clock,
......
......@@ -256,6 +256,7 @@ public final class ExoPlayerFactory {
/* analyticsCollector= */ null,
/* useLazyPreparation= */ true,
SeekParameters.DEFAULT,
new DefaultLivePlaybackSpeedControl.Builder().build(),
ExoPlayer.DEFAULT_RELEASE_TIMEOUT_MS,
/* pauseAtEndOfMediaItems= */ false,
Clock.DEFAULT,
......
......@@ -117,6 +117,7 @@ import java.util.concurrent.TimeoutException;
* loads and other initial preparation steps happen immediately. If true, these initial
* preparations are triggered only when the player starts buffering the media.
* @param seekParameters The {@link SeekParameters}.
* @param livePlaybackSpeedControl The {@link LivePlaybackSpeedControl}.
* @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 clock The {@link Clock}.
......@@ -133,6 +134,7 @@ import java.util.concurrent.TimeoutException;
@Nullable AnalyticsCollector analyticsCollector,
boolean useLazyPreparation,
SeekParameters seekParameters,
LivePlaybackSpeedControl livePlaybackSpeedControl,
long releaseTimeoutMs,
boolean pauseAtEndOfMediaItems,
Clock clock,
......@@ -182,6 +184,7 @@ import java.util.concurrent.TimeoutException;
shuffleModeEnabled,
analyticsCollector,
seekParameters,
livePlaybackSpeedControl,
releaseTimeoutMs,
pauseAtEndOfMediaItems,
applicationLooper,
......
......@@ -178,6 +178,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
private final PlaybackInfoUpdateListener playbackInfoUpdateListener;
private final MediaPeriodQueue queue;
private final MediaSourceList mediaSourceList;
private final LivePlaybackSpeedControl livePlaybackSpeedControl;
private final long releaseTimeoutMs;
@SuppressWarnings("unused")
......@@ -215,6 +216,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
boolean shuffleModeEnabled,
@Nullable AnalyticsCollector analyticsCollector,
SeekParameters seekParameters,
LivePlaybackSpeedControl livePlaybackSpeedControl,
long releaseTimeoutMs,
boolean pauseAtEndOfWindow,
Looper applicationLooper,
......@@ -229,6 +231,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
this.repeatMode = repeatMode;
this.shuffleModeEnabled = shuffleModeEnabled;
this.seekParameters = seekParameters;
this.livePlaybackSpeedControl = livePlaybackSpeedControl;
this.releaseTimeoutMs = releaseTimeoutMs;
this.pauseAtEndOfWindow = pauseAtEndOfWindow;
this.clock = clock;
......
......@@ -114,6 +114,7 @@ public class SimpleExoPlayer extends BasePlayer
@Renderer.VideoScalingMode private int videoScalingMode;
private boolean useLazyPreparation;
private SeekParameters seekParameters;
private LivePlaybackSpeedControl livePlaybackSpeedControl;
private long releaseTimeoutMs;
private long detachSurfaceTimeoutMs;
private boolean pauseAtEndOfMediaItems;
......@@ -137,6 +138,7 @@ public class SimpleExoPlayer extends BasePlayer
* <li>{@link MediaSourceFactory}: {@link DefaultMediaSourceFactory}
* <li>{@link LoadControl}: {@link DefaultLoadControl}
* <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
* Looper} of the application's main thread if the current thread doesn't have a {@link
* Looper}
......@@ -246,6 +248,7 @@ public class SimpleExoPlayer extends BasePlayer
videoScalingMode = Renderer.VIDEO_SCALING_MODE_DEFAULT;
useLazyPreparation = true;
seekParameters = SeekParameters.DEFAULT;
livePlaybackSpeedControl = new DefaultLivePlaybackSpeedControl.Builder().build();
clock = Clock.DEFAULT;
throwWhenStuckBuffering = true;
releaseTimeoutMs = ExoPlayer.DEFAULT_RELEASE_TIMEOUT_MS;
......@@ -519,14 +522,30 @@ public class SimpleExoPlayer extends BasePlayer
}
/**
* 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.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*
* @param throwWhenStuckBuffering Whether to throw when the player detects it's stuck buffering.
* @return This builder.
* @throws IllegalStateException If {@link #build()} has already been called.
*/
public Builder experimentalSetThrowWhenStuckBuffering(boolean throwWhenStuckBuffering) {
Assertions.checkState(!buildCalled);
this.throwWhenStuckBuffering = throwWhenStuckBuffering;
return this;
}
......@@ -677,6 +696,7 @@ public class SimpleExoPlayer extends BasePlayer
analyticsCollector,
builder.useLazyPreparation,
builder.seekParameters,
builder.livePlaybackSpeedControl,
builder.releaseTimeoutMs,
builder.pauseAtEndOfMediaItems,
builder.clock,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment