Commit a02a75ba by Oliver Woodman

Fix audio focus

parent f5c3b302
...@@ -163,11 +163,9 @@ public final class AudioFocusManager { ...@@ -163,11 +163,9 @@ public final class AudioFocusManager {
} }
} }
if (playerState == Player.STATE_IDLE) { return playerState == Player.STATE_IDLE
return PLAYER_COMMAND_WAIT_FOR_CALLBACK; ? handleIdle(playWhenReady)
} else { : handlePrepare(playWhenReady);
return handlePrepare(playWhenReady);
}
} }
/** /**
...@@ -199,12 +197,9 @@ public final class AudioFocusManager { ...@@ -199,12 +197,9 @@ public final class AudioFocusManager {
if (!playWhenReady) { if (!playWhenReady) {
abandonAudioFocus(); abandonAudioFocus();
return PLAYER_COMMAND_DO_NOT_PLAY; return PLAYER_COMMAND_DO_NOT_PLAY;
} else if (playerState != Player.STATE_IDLE) {
return requestAudioFocus();
} }
return focusGain != C.AUDIOFOCUS_NONE
? PLAYER_COMMAND_WAIT_FOR_CALLBACK return playerState == Player.STATE_IDLE ? handleIdle(playWhenReady) : requestAudioFocus();
: PLAYER_COMMAND_PLAY_WHEN_READY;
} }
/** Called by the player as part of {@link ExoPlayer#stop(boolean)}. */ /** Called by the player as part of {@link ExoPlayer#stop(boolean)}. */
...@@ -218,6 +213,11 @@ public final class AudioFocusManager { ...@@ -218,6 +213,11 @@ public final class AudioFocusManager {
// Internal methods. // Internal methods.
@PlayerCommand
private int handleIdle(boolean playWhenReady) {
return playWhenReady ? PLAYER_COMMAND_PLAY_WHEN_READY : PLAYER_COMMAND_DO_NOT_PLAY;
}
private @PlayerCommand int requestAudioFocus() { private @PlayerCommand int requestAudioFocus() {
int focusRequestResult; int focusRequestResult;
......
...@@ -58,7 +58,7 @@ public class AudioFocusManagerTest { ...@@ -58,7 +58,7 @@ public class AudioFocusManagerTest {
assertThat( assertThat(
audioFocusManager.setAudioAttributes( audioFocusManager.setAudioAttributes(
/* audioAttributes= */ null, /* playWhenReady= */ false, Player.STATE_IDLE)) /* audioAttributes= */ null, /* playWhenReady= */ false, Player.STATE_IDLE))
.isEqualTo(PLAYER_COMMAND_WAIT_FOR_CALLBACK); .isEqualTo(PLAYER_COMMAND_DO_NOT_PLAY);
assertThat( assertThat(
audioFocusManager.setAudioAttributes( audioFocusManager.setAudioAttributes(
/* audioAttributes= */ null, /* playWhenReady= */ true, Player.STATE_READY)) /* audioAttributes= */ null, /* playWhenReady= */ true, Player.STATE_READY))
...@@ -148,7 +148,7 @@ public class AudioFocusManagerTest { ...@@ -148,7 +148,7 @@ public class AudioFocusManagerTest {
assertThat( assertThat(
audioFocusManager.setAudioAttributes( audioFocusManager.setAudioAttributes(
media, /* playWhenReady= */ true, Player.STATE_IDLE)) media, /* playWhenReady= */ true, Player.STATE_IDLE))
.isEqualTo(PLAYER_COMMAND_WAIT_FOR_CALLBACK); .isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
assertThat(Shadows.shadowOf(audioManager).getLastAudioFocusRequest()).isNull(); assertThat(Shadows.shadowOf(audioManager).getLastAudioFocusRequest()).isNull();
assertThat(audioFocusManager.handlePrepare(/* playWhenReady= */ true)) assertThat(audioFocusManager.handlePrepare(/* playWhenReady= */ true))
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY); .isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
......
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