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

View File

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

View File

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

View File

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

View File

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