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 f714475e7a..435852b1ab 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 @@ -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}. + * + *

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);