Add experimentalSetForegroundModeTimeoutMs on SimpleExoPlayer

This is necessary to migrate apps which are using
ExoPlayer.Builder.experimentalSetForegroundModeTimeoutMs
from ExoPlayerImpl to SimpleExoPlayer.

PiperOrigin-RevId: 368657557
This commit is contained in:
kimvde 2021-04-15 17:41:10 +01:00 committed by Oliver Woodman
parent 3ab344c218
commit b0260f7cb8

View file

@ -98,6 +98,7 @@ public class SimpleExoPlayer extends BasePlayer
private final RenderersFactory renderersFactory;
private Clock clock;
private long foregroundModeTimeoutMs;
private TrackSelector trackSelector;
private MediaSourceFactory mediaSourceFactory;
private LoadControl loadControl;
@ -252,6 +253,20 @@ public class SimpleExoPlayer extends BasePlayer
detachSurfaceTimeoutMs = DEFAULT_DETACH_SURFACE_TIMEOUT_MS;
}
/**
* 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.
*
* @param timeoutMs The time limit in milliseconds.
*/
public Builder experimentalSetForegroundModeTimeoutMs(long timeoutMs) {
foregroundModeTimeoutMs = timeoutMs;
return this;
}
/**
* Sets the {@link TrackSelector} that will be used by the player.
*
@ -704,6 +719,9 @@ public class SimpleExoPlayer extends BasePlayer
additionalPermanentAvailableCommands);
player.addListener(componentListener);
player.addAudioOffloadListener(componentListener);
if (builder.foregroundModeTimeoutMs > 0) {
player.experimentalSetForegroundModeTimeoutMs(builder.foregroundModeTimeoutMs);
}
audioBecomingNoisyManager =
new AudioBecomingNoisyManager(builder.context, eventHandler, componentListener);