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.69k stars 405 forks source link

Support delayed focus gain when starting playback during a call #1716

Open brahmkshatriya opened 1 month ago

brahmkshatriya commented 1 month ago

Version

Media3 main branch

More version details

No response

Devices that reproduce the issue

Pixel 3, Android 14

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

  1. Start a phone call.
  2. Open the demo app. (Important to do it after the call)
  3. Try playing a media, media won't play.

Expected result

The player.getPlaybackSuppressionReason() gives PLAYBACK_SUPPRESSION_REASON_NONE even though the playback is suppressed due to audio focus loss.

Actual result

The player.getPlaybackSuppressionReason() should give PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS, since the playback is suppressed due to the phone call.

Media

Not applicable

Bug Report

tonihei commented 1 month ago

When the playback attempts to start during the phone call, it will never get the audio focus in the first place. So playback is permanently paused. When adding an EventLogger you can see that this is notified via onPlayWhenReadyChanged with PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS:

playWhenReady [eventTime=1.24, mediaPos=0.00, window=0, false, AUDIO_FOCUS_LOSS]

There is also a feature to ask for delayed focus gain in this particular case (so that playback continues automatically after the phone call), but this isn't implemented yet. Once that is done, you would indeed see a playback suppression reason change. Is this something you'd like to use? If so, we can mark this as a feature request.

brahmkshatriya commented 1 month ago

Yes, please mark it as a feature request

tonihei commented 1 month ago

Thanks, renamed the issue to reflect the feature request. See also [internal b/300916151] that tracks the same feature.