diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java
index f8fcec9571..1bf52ebf29 100644
--- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java
+++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java
@@ -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 {
*
{@link MediaSourceFactory}: {@link DefaultMediaSourceFactory}
* {@link LoadControl}: {@link DefaultLoadControl}
* {@link BandwidthMeter}: {@link DefaultBandwidthMeter#getSingletonInstance(Context)}
+ * {@link LivePlaybackSpeedControl}: {@link DefaultLivePlaybackSpeedControl}
* {@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;
@@ -385,6 +388,20 @@ public interface ExoPlayer extends Player {
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
* purposes.
@@ -418,6 +435,7 @@ public interface ExoPlayer extends Player {
analyticsCollector,
useLazyPreparation,
seekParameters,
+ livePlaybackSpeedControl,
releaseTimeoutMs,
pauseAtEndOfMediaItems,
clock,
diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerFactory.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerFactory.java
index 7ce6073ef3..9a208a94ae 100644
--- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerFactory.java
+++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerFactory.java
@@ -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,
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 4167307da3..9820d061aa 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
@@ -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,
diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java
index 875bf2dc44..9ee50e1f89 100644
--- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java
+++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java
@@ -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;
diff --git a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java
index 7f5384442e..aa79459e06 100644
--- a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java
+++ b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java
@@ -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
* {@link MediaSourceFactory}: {@link DefaultMediaSourceFactory}
* {@link LoadControl}: {@link DefaultLoadControl}
* {@link BandwidthMeter}: {@link DefaultBandwidthMeter#getSingletonInstance(Context)}
+ * {@link LivePlaybackSpeedControl}: {@link DefaultLivePlaybackSpeedControl}
* {@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;
@@ -518,6 +521,20 @@ public class SimpleExoPlayer extends BasePlayer
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.
*
@@ -525,8 +542,10 @@ public class SimpleExoPlayer extends BasePlayer
*
* @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,