Rename the APIs for playback suppression due to unsuitable output.

The APIs /related fields for playback suppression due to unsuitable output should be renamed from '..SuppressPlaybackWhenNoSuitableOutputAvailable' to '..SuppressPlaybackOnUnsuitableOutput'

PiperOrigin-RevId: 540555715
This commit is contained in:
Googler 2023-06-15 13:49:22 +01:00 committed by Marc Baechinger
parent 3ce6c06169
commit 42915e9a58
5 changed files with 39 additions and 66 deletions

View File

@ -16,15 +16,15 @@
* ExoPlayer:
* Add suppression of playback on unsuitable audio output devices (e.g. the
built-in speaker on Wear OS devices) when this feature is enabled via
`ExoPlayer.Builder.setSuppressPlaybackWhenNoSuitableOutputAvailable`.
The playback suppression reason will be updated as
`ExoPlayer.Builder.setSuppressPlaybackOnUnsuitableOutput`. The playback
suppression reason will be updated as
`Player.PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT` if playback
is attempted when no suitable audio outputs are available.
* Add handling for auto-resume or auto-pause of playback when audio output
devices are added or removed dynamically during suppressed or ongoing
playback when the playback suppression due to no suitable output has
been enabled via
`ExoPlayer.Builder.setSuppressPlaybackWhenNoSuitableOutputAvailable`.
`ExoPlayer.Builder.setSuppressPlaybackOnUnsuitableOutput`.
* Fix seeking issues in AC4 streams caused by not identifying decode-only
samples correctly
([#11000](https://github.com/google/ExoPlayer/issues/11000)).

View File

@ -493,7 +493,7 @@ public interface ExoPlayer extends Player {
/* package */ boolean usePlatformDiagnostics;
@Nullable /* package */ Looper playbackLooper;
/* package */ boolean buildCalled;
/* package */ boolean suppressPlaybackWhenNoSuitableOutputAvailable;
/* package */ boolean suppressPlaybackOnUnsuitableOutput;
/**
* Creates a builder.
@ -714,27 +714,26 @@ public interface ExoPlayer extends Player {
}
/**
* Sets whether the player should suppress playback when a suitable audio output is not
* available. An example of an unsuitable audio output is the built-in speaker on a Wear OS
* device (unless it is explicitly selected by the user).
* Sets whether the player should suppress playback that is attempted on an unsuitable output.
* An example of an unsuitable audio output is the built-in speaker on a Wear OS device (unless
* it is explicitly selected by the user).
*
* <p>If called with {@code suppressPlaybackWhenNoSuitableOutputAvailable = true}, then a
* playback attempt while no suitable output is available will result in calls to {@link
* <p>If called with {@code suppressPlaybackOnUnsuitableOutput = true}, then a playback attempt
* on an unsuitable audio output will result in calls to {@link
* Player.Listener#onPlaybackSuppressionReasonChanged(int)} with the value {@link
* Player#PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT}.
*
* @param suppressPlaybackWhenNoSuitableOutputAvailable Whether the player should suppress the
* playback when suitable media route is not available.
* @param suppressPlaybackOnUnsuitableOutput Whether the player should suppress the playback
* when it is attempted on an unsuitable output.
* @return This builder.
* @throws IllegalStateException If {@link #build()} has already been called.
*/
@CanIgnoreReturnValue
@UnstableApi
public Builder setSuppressPlaybackWhenNoSuitableOutputAvailable(
boolean suppressPlaybackWhenNoSuitableOutputAvailable) {
public Builder setSuppressPlaybackOnUnsuitableOutput(
boolean suppressPlaybackOnUnsuitableOutput) {
checkState(!buildCalled);
this.suppressPlaybackWhenNoSuitableOutputAvailable =
suppressPlaybackWhenNoSuitableOutputAvailable;
this.suppressPlaybackOnUnsuitableOutput = suppressPlaybackOnUnsuitableOutput;
return this;
}

View File

@ -176,7 +176,7 @@ import java.util.concurrent.TimeoutException;
private final WifiLockManager wifiLockManager;
private final long detachSurfaceTimeoutMs;
@Nullable private AudioManager audioManager;
private final boolean suppressPlaybackWhenNoSuitableOutputAvailable;
private final boolean suppressPlaybackOnUnsuitableOutput;
private @RepeatMode int repeatMode;
private boolean shuffleModeEnabled;
@ -279,8 +279,7 @@ import java.util.concurrent.TimeoutException;
this.applicationLooper = builder.looper;
this.clock = builder.clock;
this.wrappingPlayer = wrappingPlayer == null ? this : wrappingPlayer;
this.suppressPlaybackWhenNoSuitableOutputAvailable =
builder.suppressPlaybackWhenNoSuitableOutputAvailable;
this.suppressPlaybackOnUnsuitableOutput = builder.suppressPlaybackOnUnsuitableOutput;
listeners =
new ListenerSet<>(
applicationLooper,
@ -389,7 +388,7 @@ import java.util.concurrent.TimeoutException;
audioBecomingNoisyManager.setEnabled(builder.handleAudioBecomingNoisy);
audioFocusManager = new AudioFocusManager(builder.context, eventHandler, componentListener);
audioFocusManager.setAudioAttributes(builder.handleAudioFocus ? audioAttributes : null);
if (suppressPlaybackWhenNoSuitableOutputAvailable) {
if (suppressPlaybackOnUnsuitableOutput) {
audioManager = (AudioManager) applicationContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.registerAudioDeviceCallback(
new NoSuitableOutputPlaybackSuppressionAudioDeviceCallback(), /* handler= */ null);
@ -2774,7 +2773,7 @@ import java.util.concurrent.TimeoutException;
if (playWhenReady && playerCommand != AudioFocusManager.PLAYER_COMMAND_PLAY_WHEN_READY) {
return Player.PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS;
}
if (suppressPlaybackWhenNoSuitableOutputAvailable) {
if (suppressPlaybackOnUnsuitableOutput) {
if (playWhenReady && !hasSupportedAudioOutput()) {
return Player.PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT;
}

View File

@ -13141,9 +13141,7 @@ public final class ExoPlayerTest {
setupConnectedAudioOutput(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER);
List<Integer> playbackSuppressionList = new ArrayList<>();
ExoPlayer player =
new TestExoPlayerBuilder(context)
.setSuppressOutputWhenNoSuitableOutputAvailable(true)
.build();
new TestExoPlayerBuilder(context).setSuppressPlaybackOnUnsuitableOutput(true).build();
player.setMediaItem(
MediaItem.fromUri("asset:///media/mp4/sample_with_increasing_timestamps_360p.mp4"));
player.addListener(
@ -13177,9 +13175,7 @@ public final class ExoPlayerTest {
AudioDeviceInfo.TYPE_BUILTIN_SPEAKER, AudioDeviceInfo.TYPE_BLUETOOTH_A2DP);
List<Integer> playbackSuppressionList = new ArrayList<>();
ExoPlayer player =
new TestExoPlayerBuilder(context)
.setSuppressOutputWhenNoSuitableOutputAvailable(true)
.build();
new TestExoPlayerBuilder(context).setSuppressPlaybackOnUnsuitableOutput(true).build();
player.setMediaItem(
MediaItem.fromUri("asset:///media/mp4/sample_with_increasing_timestamps_360p.mp4"));
player.addListener(
@ -13214,9 +13210,7 @@ public final class ExoPlayerTest {
setupConnectedAudioOutput(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER);
List<Integer> playbackSuppressionList = new ArrayList<>();
ExoPlayer player =
new TestExoPlayerBuilder(context)
.setSuppressOutputWhenNoSuitableOutputAvailable(true)
.build();
new TestExoPlayerBuilder(context).setSuppressPlaybackOnUnsuitableOutput(true).build();
player.setMediaItem(
MediaItem.fromUri("asset:///media/mp4/sample_with_increasing_timestamps_360p.mp4"));
player.addListener(
@ -13252,9 +13246,7 @@ public final class ExoPlayerTest {
AudioDeviceInfo.TYPE_BUILTIN_SPEAKER, AudioDeviceInfo.TYPE_BLUETOOTH_A2DP);
List<Integer> playbackSuppressionList = new ArrayList<>();
ExoPlayer player =
new TestExoPlayerBuilder(context)
.setSuppressOutputWhenNoSuitableOutputAvailable(true)
.build();
new TestExoPlayerBuilder(context).setSuppressPlaybackOnUnsuitableOutput(true).build();
player.setMediaItem(
MediaItem.fromUri("asset:///media/mp4/sample_with_increasing_timestamps_360p.mp4"));
player.addListener(
@ -13279,8 +13271,8 @@ public final class ExoPlayerTest {
/**
* Tests playback suppression for playback with only unsuitable route (e.g. builtin speaker) on
* Wear OS but {@link ExoPlayer.Builder#setSuppressPlaybackWhenNoSuitableOutputAvailable(boolean)}
* is not called with parameter as TRUE.
* Wear OS but {@link ExoPlayer.Builder#setSuppressPlaybackOnUnsuitableOutput(boolean)} is not
* called with parameter as TRUE.
*/
@Test
public void
@ -13319,9 +13311,7 @@ public final class ExoPlayerTest {
addWatchAsSystemFeature();
setupConnectedAudioOutput(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER);
ExoPlayer player =
new TestExoPlayerBuilder(context)
.setSuppressOutputWhenNoSuitableOutputAvailable(true)
.build();
new TestExoPlayerBuilder(context).setSuppressPlaybackOnUnsuitableOutput(true).build();
player.setMediaItem(
MediaItem.fromUri("asset:///media/mp4/sample_with_increasing_timestamps_360p.mp4"));
player.prepare();
@ -13358,9 +13348,7 @@ public final class ExoPlayerTest {
addWatchAsSystemFeature();
setupConnectedAudioOutput(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER);
ExoPlayer player =
new TestExoPlayerBuilder(context)
.setSuppressOutputWhenNoSuitableOutputAvailable(true)
.build();
new TestExoPlayerBuilder(context).setSuppressPlaybackOnUnsuitableOutput(true).build();
player.setMediaItem(
MediaItem.fromUri("asset:///media/mp4/sample_with_increasing_timestamps_360p.mp4"));
player.prepare();
@ -13394,9 +13382,7 @@ public final class ExoPlayerTest {
addWatchAsSystemFeature();
setupConnectedAudioOutput(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER);
ExoPlayer player =
new TestExoPlayerBuilder(context)
.setSuppressOutputWhenNoSuitableOutputAvailable(true)
.build();
new TestExoPlayerBuilder(context).setSuppressPlaybackOnUnsuitableOutput(true).build();
player.setMediaItem(
MediaItem.fromUri("asset:///media/mp4/sample_with_increasing_timestamps_360p.mp4"));
player.prepare();
@ -13429,9 +13415,7 @@ public final class ExoPlayerTest {
throws Exception {
setupConnectedAudioOutput(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER);
ExoPlayer player =
new TestExoPlayerBuilder(context)
.setSuppressOutputWhenNoSuitableOutputAvailable(true)
.build();
new TestExoPlayerBuilder(context).setSuppressPlaybackOnUnsuitableOutput(true).build();
player.setMediaItem(
MediaItem.fromUri("asset:///media/mp4/sample_with_increasing_timestamps_360p.mp4"));
player.prepare();
@ -13469,9 +13453,7 @@ public final class ExoPlayerTest {
setupConnectedAudioOutput(
AudioDeviceInfo.TYPE_BUILTIN_SPEAKER, AudioDeviceInfo.TYPE_BLUETOOTH_A2DP);
ExoPlayer player =
new TestExoPlayerBuilder(context)
.setSuppressOutputWhenNoSuitableOutputAvailable(true)
.build();
new TestExoPlayerBuilder(context).setSuppressPlaybackOnUnsuitableOutput(true).build();
player.setMediaItem(
MediaItem.fromUri("asset:///media/mp4/sample_with_increasing_timestamps_360p.mp4"));
player.prepare();
@ -13508,9 +13490,7 @@ public final class ExoPlayerTest {
AudioDeviceInfo.TYPE_BUS,
AudioDeviceInfo.TYPE_BLUETOOTH_A2DP);
ExoPlayer player =
new TestExoPlayerBuilder(context)
.setSuppressOutputWhenNoSuitableOutputAvailable(true)
.build();
new TestExoPlayerBuilder(context).setSuppressPlaybackOnUnsuitableOutput(true).build();
player.setMediaItem(
MediaItem.fromUri("asset:///media/mp4/sample_with_increasing_timestamps_360p.mp4"));
player.prepare();
@ -13547,9 +13527,7 @@ public final class ExoPlayerTest {
AudioDeviceInfo.TYPE_BLE_SPEAKER,
AudioDeviceInfo.TYPE_BLUETOOTH_A2DP);
ExoPlayer player =
new TestExoPlayerBuilder(context)
.setSuppressOutputWhenNoSuitableOutputAvailable(true)
.build();
new TestExoPlayerBuilder(context).setSuppressPlaybackOnUnsuitableOutput(true).build();
player.setMediaItem(
MediaItem.fromUri("asset:///media/mp4/sample_with_increasing_timestamps_360p.mp4"));
player.prepare();
@ -13582,9 +13560,7 @@ public final class ExoPlayerTest {
setupConnectedAudioOutput(
AudioDeviceInfo.TYPE_BUILTIN_SPEAKER, AudioDeviceInfo.TYPE_BLUETOOTH_A2DP);
ExoPlayer player =
new TestExoPlayerBuilder(context)
.setSuppressOutputWhenNoSuitableOutputAvailable(true)
.build();
new TestExoPlayerBuilder(context).setSuppressPlaybackOnUnsuitableOutput(true).build();
player.setMediaItem(
MediaItem.fromUri("asset:///media/mp4/sample_with_increasing_timestamps_360p.mp4"));
player.prepare();

View File

@ -303,17 +303,16 @@ public class TestExoPlayerBuilder {
}
/**
* See {@link ExoPlayer.Builder#setSuppressPlaybackWhenNoSuitableOutputAvailable(boolean)} for
* details.
* See {@link ExoPlayer.Builder#setSuppressPlaybackOnUnsuitableOutput(boolean)} for details.
*
* @param suppressPlaybackWhenNoSuitableOutputAvailable Whether the player should suppress the
* playback when suitable media route is not available.
* @param suppressPlaybackOnUnsuitableOutput Whether the player should suppress the playback when
* it is attempted on an unsuitable output.
* @return This builder.
*/
@CanIgnoreReturnValue
public TestExoPlayerBuilder setSuppressOutputWhenNoSuitableOutputAvailable(
boolean suppressPlaybackWhenNoSuitableOutputAvailable) {
this.suppressPlaybackWhenUnsuitableOutput = suppressPlaybackWhenNoSuitableOutputAvailable;
public TestExoPlayerBuilder setSuppressPlaybackOnUnsuitableOutput(
boolean suppressPlaybackOnUnsuitableOutput) {
this.suppressPlaybackWhenUnsuitableOutput = suppressPlaybackOnUnsuitableOutput;
return this;
}
@ -354,7 +353,7 @@ public class TestExoPlayerBuilder {
.setSeekBackIncrementMs(seekBackIncrementMs)
.setSeekForwardIncrementMs(seekForwardIncrementMs)
.setDeviceVolumeControlEnabled(deviceVolumeControlEnabled)
.setSuppressPlaybackWhenNoSuitableOutputAvailable(suppressPlaybackWhenUnsuitableOutput);
.setSuppressPlaybackOnUnsuitableOutput(suppressPlaybackWhenUnsuitableOutput);
if (mediaSourceFactory != null) {
builder.setMediaSourceFactory(mediaSourceFactory);
}