androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
Apache License 2.0
1.34k stars 315 forks source link

EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED and PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS are not being sent when audio focus is lost #1470

Closed aljohnston112 closed 1 week ago

aljohnston112 commented 1 week ago

Version

Media3 main branch

More version details

implementation "androidx.media3:media3-common:1.2.0"
implementation "androidx.media3:media3-exoplayer:1.2.0"
implementation "androidx.media3:media3-session:1.2.0"

Devices that reproduce the issue

Pixel 8 Android 14

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

  1. Create a Player with setAudioAttributes' handleAudioFocus parameter to true.
  2. Set up a MediaSession and start playback.
  3. Have another app take audio focus.

Expected result

As described here: https://github.com/google/ExoPlayer/issues/10293

When playback is stopped due to loss of audio focus, Player.Listener.onPlaybackSuppressionReasonChanged will be called with reason Player.PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS.

The event included in Player.Listener.onEvents() with key EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED.

Actual result

Neither of the two expected results happen.

Media

Not applicable

Bug Report

aljohnston112 commented 1 week ago

I did find that onPlayWhenReadyChanged is triggered with reason PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS when audio focus is lost. If that is what the intended behavior is, feel free to close this ticket.

tonihei commented 1 week ago

Yes, this is the intended behavior. Note that there is a difference between onPlaybackSuppressionReasonChanged(PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS) (= transient, short-lived suppression with automatic resumption) and onPlayWhenReadyChanged(PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS) (=a permanent focus loss, no automatic resumption).