Commit 1ef3efaa by olly Committed by Oliver Woodman

Automated g4 rollback of changelist 217356705.

*** Reason for rollback ***

Photos regression is resolved by []

*** Original change description ***

Automated g4 rollback of changelist 217189082.

*** Reason for rollback ***

Broke photos (b/117818304)

*** Original change description ***

Add ExoPlayer.setForegroundMode

Issue: #2826

***

***

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=217773278
parent 38057170
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
### dev-v2 (not yet released) ### ### dev-v2 (not yet released) ###
* Improve decoder re-use between playbacks. TODO: Write and link a blog post
here ([#2826](https://github.com/google/ExoPlayer/issues/2826)).
* Improve initial bandwidth meter estimates using the current country and * Improve initial bandwidth meter estimates using the current country and
network type. network type.
* Do not retry failed loads whose error is `FileNotFoundException`. * Do not retry failed loads whose error is `FileNotFoundException`.
......
...@@ -209,4 +209,34 @@ public interface ExoPlayer extends Player { ...@@ -209,4 +209,34 @@ public interface ExoPlayer extends Player {
/** Returns the currently active {@link SeekParameters} of the player. */ /** Returns the currently active {@link SeekParameters} of the player. */
SeekParameters getSeekParameters(); SeekParameters getSeekParameters();
/**
* Sets whether the player is allowed to keep holding limited resources such as video decoders,
* even when in the idle state. By doing so, the player may be able to reduce latency when
* starting to play another piece of content for which the same resources are required.
*
* <p>This mode should be used with caution, since holding limited resources may prevent other
* players of media components from acquiring them. It should only be enabled when <em>both</em>
* of the following conditions are true:
*
* <ul>
* <li>The application that owns the player is in the foreground.
* <li>The player is used in a way that may benefit from foreground mode. For this to be true,
* the same player instance must be used to play multiple pieces of content, and there must
* be gaps between the playbacks (i.e. {@link #stop} is called to halt one playback, and
* {@link #prepare} is called some time later to start a new one).
* </ul>
*
* <p>Note that foreground mode is <em>not</em> useful for switching between content without gaps
* between the playbacks. For this use case {@link #stop} does not need to be called, and simply
* calling {@link #prepare} for the new media will cause limited resources to be retained even if
* foreground mode is not enabled.
*
* <p>If foreground mode is enabled, it's the application's responsibility to disable it when the
* conditions described above no longer hold.
*
* @param foregroundMode Whether the player is allowed to keep limited resources even when in the
* idle state.
*/
void setForegroundMode(boolean foregroundMode);
} }
...@@ -71,6 +71,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -71,6 +71,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
private int pendingOperationAcks; private int pendingOperationAcks;
private boolean hasPendingPrepare; private boolean hasPendingPrepare;
private boolean hasPendingSeek; private boolean hasPendingSeek;
private boolean foregroundMode;
private PlaybackParameters playbackParameters; private PlaybackParameters playbackParameters;
private SeekParameters seekParameters; private SeekParameters seekParameters;
private @Nullable ExoPlaybackException playbackError; private @Nullable ExoPlaybackException playbackError;
...@@ -360,6 +361,14 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -360,6 +361,14 @@ import java.util.concurrent.CopyOnWriteArraySet;
} }
@Override @Override
public void setForegroundMode(boolean foregroundMode) {
if (this.foregroundMode != foregroundMode) {
this.foregroundMode = foregroundMode;
internalPlayer.setForegroundMode(foregroundMode);
}
}
@Override
public void stop(boolean reset) { public void stop(boolean reset) {
if (reset) { if (reset) {
playbackError = null; playbackError = null;
......
...@@ -959,6 +959,11 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -959,6 +959,11 @@ public class SimpleExoPlayer extends BasePlayer
} }
@Override @Override
public void setForegroundMode(boolean foregroundMode) {
player.setForegroundMode(foregroundMode);
}
@Override
public void stop(boolean reset) { public void stop(boolean reset) {
verifyApplicationThread(); verifyApplicationThread();
player.stop(reset); player.stop(reset);
......
...@@ -267,4 +267,9 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer { ...@@ -267,4 +267,9 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
public long getContentBufferedPosition() { public long getContentBufferedPosition() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public void setForegroundMode(boolean foregroundMode) {
throw new UnsupportedOperationException();
}
} }
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