Fix for #5055 - Cannot disable audio focus after enabled.
This fixes an issue where disabling audio focus handling while audio focus is held would not release audio focus. A new test was added for this situation. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=220316866
This commit is contained in:
parent
abb7d8a2d5
commit
0c4d0ee1c1
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
### dev-v2 (not yet released) ###
|
### dev-v2 (not yet released) ###
|
||||||
|
|
||||||
|
* Fix issue where audio focus handling could not be disabled after enabling
|
||||||
|
it ([#5055](https://github.com/google/ExoPlayer/issues/5055)).
|
||||||
* Support for playing spherical videos on Daydream.
|
* Support for playing spherical videos on Daydream.
|
||||||
* Improve decoder re-use between playbacks. TODO: Write and link a blog post
|
* Improve decoder re-use between playbacks. TODO: Write and link a blog post
|
||||||
here ([#2826](https://github.com/google/ExoPlayer/issues/2826)).
|
here ([#2826](https://github.com/google/ExoPlayer/issues/2826)).
|
||||||
|
@ -141,10 +141,6 @@ public final class AudioFocusManager {
|
|||||||
*/
|
*/
|
||||||
public @PlayerCommand int setAudioAttributes(
|
public @PlayerCommand int setAudioAttributes(
|
||||||
@Nullable AudioAttributes audioAttributes, boolean playWhenReady, int playerState) {
|
@Nullable AudioAttributes audioAttributes, boolean playWhenReady, int playerState) {
|
||||||
if (audioAttributes == null) {
|
|
||||||
return PLAYER_COMMAND_PLAY_WHEN_READY;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Util.areEqual(this.audioAttributes, audioAttributes)) {
|
if (!Util.areEqual(this.audioAttributes, audioAttributes)) {
|
||||||
this.audioAttributes = audioAttributes;
|
this.audioAttributes = audioAttributes;
|
||||||
focusGain = convertAudioAttributesToFocusGain(audioAttributes);
|
focusGain = convertAudioAttributesToFocusGain(audioAttributes);
|
||||||
|
@ -58,7 +58,38 @@ 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);
|
||||||
|
assertThat(
|
||||||
|
audioFocusManager.setAudioAttributes(
|
||||||
|
/* audioAttributes= */ null, /* playWhenReady= */ true, Player.STATE_READY))
|
||||||
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
||||||
|
ShadowAudioManager.AudioFocusRequest request =
|
||||||
|
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
||||||
|
assertThat(request).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setAudioAttributes_withNullUsage_releasesAudioFocus() {
|
||||||
|
// Create attributes and request audio focus.
|
||||||
|
AudioAttributes media = new AudioAttributes.Builder().setUsage(C.USAGE_MEDIA).build();
|
||||||
|
Shadows.shadowOf(audioManager)
|
||||||
|
.setNextFocusRequestResponse(AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
|
||||||
|
assertThat(
|
||||||
|
audioFocusManager.setAudioAttributes(
|
||||||
|
media, /* playWhenReady= */ true, Player.STATE_READY))
|
||||||
|
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
||||||
|
ShadowAudioManager.AudioFocusRequest request =
|
||||||
|
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
||||||
|
assertThat(request.durationHint).isEqualTo(AudioManager.AUDIOFOCUS_GAIN);
|
||||||
|
|
||||||
|
// Ensure that setting null audio attributes with audio focus releases audio focus.
|
||||||
|
assertThat(
|
||||||
|
audioFocusManager.setAudioAttributes(
|
||||||
|
/* audioAttributes= */ null, /* playWhenReady= */ true, Player.STATE_READY))
|
||||||
|
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
||||||
|
AudioManager.OnAudioFocusChangeListener lastRequest =
|
||||||
|
Shadows.shadowOf(audioManager).getLastAbandonedAudioFocusListener();
|
||||||
|
assertThat(lastRequest).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -296,7 +327,7 @@ public class AudioFocusManagerTest {
|
|||||||
assertThat(
|
assertThat(
|
||||||
audioFocusManager.setAudioAttributes(
|
audioFocusManager.setAudioAttributes(
|
||||||
/* audioAttributes= */ null, /* playWhenReady= */ false, Player.STATE_READY))
|
/* audioAttributes= */ null, /* playWhenReady= */ false, Player.STATE_READY))
|
||||||
.isEqualTo(PLAYER_COMMAND_PLAY_WHEN_READY);
|
.isEqualTo(PLAYER_COMMAND_DO_NOT_PLAY);
|
||||||
assertThat(Shadows.shadowOf(audioManager).getLastAbandonedAudioFocusListener()).isNull();
|
assertThat(Shadows.shadowOf(audioManager).getLastAbandonedAudioFocusListener()).isNull();
|
||||||
ShadowAudioManager.AudioFocusRequest request =
|
ShadowAudioManager.AudioFocusRequest request =
|
||||||
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
Shadows.shadowOf(audioManager).getLastAudioFocusRequest();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user