androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.71k stars 408 forks source link

Do not request audio focus if the played video has no audio #724

Open sonicdebris opened 1 year ago

sonicdebris commented 1 year ago

Use case description

When setting up exoplayer by calling ExoPlayer.setAudioAttributes(...) with handleAudioFocus set to true, the audio focus is always requested even when the video file contains no audio tracks or all audio tracks have been disabled.

This means that the burden of deciding whether the audio focus should really be requested or not is on the application, which would then need to inspect the content of the video file.

Proposed solution

When handleAudioFocus==true, Exoplayer should NOT actually request the audio focus when either the video contains no audio tracks or when all audio tracks have been disabled.

Alternatives considered

Rename handleAudioFocus argument to requestAudioFocus to at least make expectations clearer.

tonihei commented 1 year ago

(see also internal ref: b/300917087)

tonihei commented 1 year ago

Thanks for filing the issue. This has also been highlighted before (see internal ref I linked above) and I'll mark it as a feature request that should be handled by the library internally.

ryandt commented 9 months ago

I also have a few use cases where I'm using the player to auto-play video previews that contain audio but the audio is muted. It would be nice if the player only requested audio focus if there's actual audio playing.