Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
YuriPopiv opened this issue Jun 15, 2023 · 5 comments
Assignees

Comments

@YuriPopiv
Copy link

YuriPopiv commented Jun 15, 2023

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

@tonihei
Copy link
Collaborator

tonihei commented Jun 16, 2023

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.

@YuriPopiv
Copy link
Author

@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)

@tonihei
Copy link
Collaborator

tonihei commented Jun 16, 2023

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
Copy link
Collaborator

tonihei commented Jul 10, 2023

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.

oceanjules pushed a commit to androidx/media that referenced this issue Aug 15, 2023
This changes the default logic of shouldShowPlayButton to show a play
button while the playback is temporarily suppressed. This helps to
provide better UI feedback to the fact that playback stopped and
provides a quick way for users to override the suppression and attempt
to restart playback.

Some apps may want to keep the legacy behavior depending on their app's
needs. Hence, we also add a config parameter to set this behavior both
in MediaSession and our default UI components.

Issue: google/ExoPlayer#11213
PiperOrigin-RevId: 557129171
tianyif pushed a commit that referenced this issue Aug 21, 2023
This changes the default logic of shouldShowPlayButton to show a play
button while the playback is temporarily suppressed. This helps to
provide better UI feedback to the fact that playback stopped and
provides a quick way for users to override the suppression and attempt
to restart playback.

Some apps may want to keep the legacy behavior depending on their app's
needs. Hence, we also add a config parameter to set this behavior both
in MediaSession and our default UI components.

Issue: #11213
PiperOrigin-RevId: 557129171
@tonihei
Copy link
Collaborator

tonihei commented Aug 30, 2023

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

@tonihei tonihei closed this as completed Aug 30, 2023
microkatz pushed a commit to hugohlln/media that referenced this issue Sep 29, 2023
This changes the default logic of shouldShowPlayButton to show a play
button while the playback is temporarily suppressed. This helps to
provide better UI feedback to the fact that playback stopped and
provides a quick way for users to override the suppression and attempt
to restart playback.

Some apps may want to keep the legacy behavior depending on their app's
needs. Hence, we also add a config parameter to set this behavior both
in MediaSession and our default UI components.

Issue: google/ExoPlayer#11213
PiperOrigin-RevId: 557129171
@google google locked and limited conversation to collaborators Oct 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants