Commit 48d3d631 by olly Committed by Ian Baker

Add experimentalSetForegroundModeTimeoutMs

Allows to set a timeout for the setForegroundMode(false) call, different than releaseTimeoutMs.

PiperOrigin-RevId: 342980350
parent 0abdfe94
......@@ -163,6 +163,7 @@ public interface ExoPlayer extends Player {
private boolean buildCalled;
private boolean throwWhenStuckBuffering;
private long setForegroundModeTimeoutMs;
/**
* Creates a builder with a list of {@link Renderer Renderers}.
......@@ -232,6 +233,20 @@ public interface ExoPlayer extends Player {
}
/**
* Set a limit on the time a call to {@link ExoPlayer#setForegroundMode} can spend. If a call to
* {@link ExoPlayer#setForegroundMode} takes more than {@code timeoutMs} milliseconds to
* complete, the player will raise an error via {@link Player.EventListener#onPlayerError}.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*
* @param timeoutMs The time limit in milliseconds, or 0 for no limit.
*/
public Builder experimentalSetForegroundModeTimeoutMs(long timeoutMs) {
setForegroundModeTimeoutMs = timeoutMs;
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.
......@@ -441,6 +456,7 @@ public interface ExoPlayer extends Player {
clock,
looper);
player.experimentalSetForegroundModeTimeoutMs(setForegroundModeTimeoutMs);
if (!throwWhenStuckBuffering) {
player.experimentalDisableThrowWhenStuckBuffering();
}
......
......@@ -191,6 +191,20 @@ import java.util.concurrent.TimeoutException;
}
/**
* Set a limit on the time a call to {@link #setForegroundMode} can spend. If a call to {@link
* #setForegroundMode} takes more than {@code timeoutMs} milliseconds to complete, the player will
* raise an error via {@link Player.EventListener#onPlayerError}.
*
* <p>This method is experimental, and will be renamed or removed in a future release. It should
* only be called before the player is used.
*
* @param timeoutMs The time limit in milliseconds, or 0 for no limit.
*/
public void experimentalSetForegroundModeTimeoutMs(long timeoutMs) {
internalPlayer.experimentalSetForegroundModeTimeoutMs(timeoutMs);
}
/**
* Configures the player to not throw when it detects it's stuck buffering.
*
* <p>This method is experimental, and will be renamed or removed in a future release. It should
......
......@@ -205,6 +205,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
@Nullable private ExoPlaybackException pendingRecoverableError;
private boolean throwWhenStuckBuffering;
private long setForegroundModeTimeoutMs;
public ExoPlayerImplInternal(
Renderer[] renderers,
......@@ -233,6 +234,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
this.seekParameters = seekParameters;
this.livePlaybackSpeedControl = livePlaybackSpeedControl;
this.releaseTimeoutMs = releaseTimeoutMs;
this.setForegroundModeTimeoutMs = releaseTimeoutMs;
this.pauseAtEndOfWindow = pauseAtEndOfWindow;
this.clock = clock;
......@@ -267,6 +269,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
handler = clock.createHandler(playbackLooper, this);
}
public void experimentalSetForegroundModeTimeoutMs(long setForegroundModeTimeoutMs) {
this.setForegroundModeTimeoutMs = setForegroundModeTimeoutMs;
}
public void experimentalDisableThrowWhenStuckBuffering() {
throwWhenStuckBuffering = false;
}
......@@ -393,7 +399,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
handler
.obtainMessage(MSG_SET_FOREGROUND_MODE, /* foregroundMode */ 0, 0, processedFlag)
.sendToTarget();
waitUninterruptibly(/* condition= */ processedFlag::get, releaseTimeoutMs);
waitUninterruptibly(/* condition= */ processedFlag::get, setForegroundModeTimeoutMs);
return processedFlag.get();
}
}
......
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