Use AudioTrack.isDirectPlaybackSupported on TVs only

Issue: #9239

#minor-release

PiperOrigin-RevId: 388437614
This commit is contained in:
andrewlewis 2021-08-03 14:10:07 +01:00 committed by Andrew Lewis
parent cc8f4dcc6b
commit 5e4cd1293e
2 changed files with 10 additions and 3 deletions

View File

@ -51,6 +51,10 @@
behavior of track and location fallback. Location fallback is currently
only supported for DASH manifests with multiple base URLs.
* Disable platform transcoding when playing content URIs on Android 12.
* Restrict use of `AudioTrack.isDirectPlaybackSupported` to TVs, to avoid
listing audio offload encodings as supported for passthrough mode on
mobile devices
([#9239](https://github.com/google/ExoPlayer/issues/9239)).
* Remove deprecated symbols:
* Remove `Player.getPlaybackError`. Use `Player.getPlayerError` instead.
* Remove `Player.getCurrentTag`. Use `Player.getCurrentMediaItem` and

View File

@ -88,9 +88,12 @@ public final class AudioCapabilities {
&& Global.getInt(context.getContentResolver(), EXTERNAL_SURROUND_SOUND_KEY, 0) == 1) {
return EXTERNAL_SURROUND_SOUND_CAPABILITIES;
}
if (Util.SDK_INT >= 29) {
// AudioTrack.isDirectPlaybackSupported returns true for encodings that are supported for audio
// offload, as well as for encodings we want to list for passthrough mode. Therefore we only use
// it on TV devices, which generally shouldn't support audio offload for surround encodings.
if (Util.SDK_INT >= 29 && Util.isTv(context)) {
return new AudioCapabilities(
AudioTrackWrapperV29.getDirectPlaybackSupportedEncodingsV29(), DEFAULT_MAX_CHANNEL_COUNT);
Api29.getDirectPlaybackSupportedEncodingsV29(), DEFAULT_MAX_CHANNEL_COUNT);
}
if (intent == null || intent.getIntExtra(AudioManager.EXTRA_AUDIO_PLUG_STATE, 0) == 0) {
return DEFAULT_AUDIO_CAPABILITIES;
@ -185,7 +188,7 @@ public final class AudioCapabilities {
}
@RequiresApi(29)
private static final class AudioTrackWrapperV29 {
private static final class Api29 {
@DoNotInline
public static int[] getDirectPlaybackSupportedEncodingsV29() {
ImmutableList.Builder<Integer> supportedEncodingsListBuilder = ImmutableList.builder();