ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

Why automatic handling of audio focus is not updating app and notification with "pause"?

Open picklepickle1 opened this issue 3 years ago • 5 comments

MediaSession is not updated when audio focus is temporarily lost For example, switching to Facebook short videos. UAMP app: music paused, notification keeps showing the pause button(like it's playing at the moment). In other cases I'm ok with setAudioAttributes(audioAttributes, handleAudioFocus = true) but there is no way to handle this case.

my notification is fully handled by com.google.android.exoplayer2.ui.PlayerNotificationManager

For example YouTubeMusic app updates the notification button and shows "play" button when focus is temporarily taken by facebook. The same issue when receiving a phone call. Android Auto buttons work the same.

Event EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED is not helping

picklepickle1 avatar Jun 15 '23 22:06 picklepickle1

This is an interesting question and something we couldn't find a good answer for in previous discussions. It all comes down to: "what do you expect to happen when you use the play/pause button while audio focus is lost transiently (e.g. during phone call or notification sound)?"

The two options are:

  • You want to change whether the player continues automatically after the temporary interruption. This is the current ExoPlayer logic (and because we default to continue playing, it shows a pause button to change that)
  • You want to immediately continue playback even though the temporary interruption is still ongoing. This is what you are asking for I believe? In this case, the user should see a play button to trigger this option.

The current UI behavior actually lets you do both:

  • It shows a "pause" button first, letting you pause the playback so that it won't continue after the interruption.
  • Tapping the button changes it to a "play" button that lets you start playback despite the ongoing interruption.

tonihei avatar Jun 16 '23 08:06 tonihei

@tonihei I want to achieve the same behaviour like YouTubeMusic. Example: switching to Facebook app and play videos. YouTubeMusic paused. Notification is also paused (play button is shown)

Because currently when audio focus is lost transiently UAMP keeps showing the notification with pause button (like it's playing at the moment and that looks weird)

picklepickle1 avatar Jun 16 '23 09:06 picklepickle1

Yes, I understand what you are asking for. My post was trying to explain the decision issue behind: "which button should we show the user?" and that there is no obvious right or wrong way of doing this.

I'll try to see if there is specific guidance we should apply by default and/or whether we can provide an option for apps to choose the behavior.

tonihei avatar Jun 16 '23 09:06 tonihei

We decided that we'll change our default logic to show a "play" button in such a case and also provide a way to override this default if desired by apps. Marking it as an enhancement to track this work.

tonihei avatar Jul 10 '23 08:07 tonihei

This is now implemented by default and will be published as part of the next Media3 release.

tonihei avatar Aug 30 '23 15:08 tonihei