Fix bogus reporting of audio focus loss
Playback cannot be suppressed if playWhenReady=false PiperOrigin-RevId: 273726084
This commit is contained in:
parent
e6fe80fa88
commit
3d0886f458
@ -1433,9 +1433,9 @@ public class SimpleExoPlayer extends BasePlayer
|
||||
private void updatePlayWhenReady(
|
||||
boolean playWhenReady, @AudioFocusManager.PlayerCommand int playerCommand) {
|
||||
int playbackSuppressionReason =
|
||||
playerCommand == AudioFocusManager.PLAYER_COMMAND_PLAY_WHEN_READY
|
||||
? Player.PLAYBACK_SUPPRESSION_REASON_NONE
|
||||
: Player.PLAYBACK_SUPPRESSION_REASON_AUDIO_FOCUS_LOSS;
|
||||
playWhenReady && playerCommand != AudioFocusManager.PLAYER_COMMAND_PLAY_WHEN_READY
|
||||
? Player.PLAYBACK_SUPPRESSION_REASON_AUDIO_FOCUS_LOSS
|
||||
: Player.PLAYBACK_SUPPRESSION_REASON_NONE;
|
||||
player.setPlayWhenReady(
|
||||
playWhenReady && playerCommand != AudioFocusManager.PLAYER_COMMAND_DO_NOT_PLAY,
|
||||
playbackSuppressionReason);
|
||||
|
@ -64,6 +64,7 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@ -2767,6 +2768,34 @@ public final class ExoPlayerTest {
|
||||
.inOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simplePlaybackHasNoPlaybackSuppression() throws Exception {
|
||||
ActionSchedule actionSchedule =
|
||||
new ActionSchedule.Builder("simplePlaybackHasNoPlaybackSuppression")
|
||||
.play()
|
||||
.waitForPlaybackState(Player.STATE_READY)
|
||||
.pause()
|
||||
.play()
|
||||
.build();
|
||||
AtomicBoolean seenPlaybackSuppression = new AtomicBoolean();
|
||||
EventListener listener =
|
||||
new EventListener() {
|
||||
@Override
|
||||
public void onPlaybackSuppressionReasonChanged(
|
||||
@Player.PlaybackSuppressionReason int playbackSuppressionReason) {
|
||||
seenPlaybackSuppression.set(true);
|
||||
}
|
||||
};
|
||||
new ExoPlayerTestRunner.Builder()
|
||||
.setActionSchedule(actionSchedule)
|
||||
.setEventListener(listener)
|
||||
.build(context)
|
||||
.start()
|
||||
.blockUntilEnded(TIMEOUT_MS);
|
||||
|
||||
assertThat(seenPlaybackSuppression.get()).isFalse();
|
||||
}
|
||||
|
||||
// Internal methods.
|
||||
|
||||
private static ActionSchedule.Builder addSurfaceSwitch(ActionSchedule.Builder builder) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user