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

How to disable media Queue button in Android Auto when playing live stream. #339

Closed
Guardiannw opened this issue Apr 19, 2023 · 9 comments
Closed
Assignees
Labels

Comments

@Guardiannw
Copy link

Question:

Under the previous version of the media library, when playing a live stream (HLS) for a radio station, the Queue button did not appear in Android Auto when playing a media item. However, after migrating to the new Media3 library, the Queue seems to be there by default. I have tried to look through the documentation, but cannot find a way to easily disable the Queue button on Android Auto. I assume it has something to do with the new implementation because it was not there for us on the old implementation. Is there any way that I can easily disable the viewing of the queue in Android Auto via the library.

@marcbaechinger

This comment was marked as spam.

@Guardiannw
Copy link
Author

Thanks @marcbaechinger for responding. I have just tried your suggestions, but unfortunately, the queue button is still there. I have also tried removing these commands in the onConnect method of the MediaLibrarySession.Callback, but the issue still persists.

@marcbaechinger
Copy link
Contributor

Ok, thanks! Will investigate.

@marcbaechinger
Copy link
Contributor

marcbaechinger commented May 3, 2023

The criteria is whether the queue is empty or not.

With Media3, the queue of the legacy session is a function of the media items added to the player. So if there is a media item playing, then the queue is never empty.

This is a regression compared to what apps can do with the legacy MediaSessionCompat API. I think we need to fix this.

I changed this issue to a bug and will update this issue when we have news.

@Guardiannw
Copy link
Author

Thanks so much for looking into this!

@DenysLoboda
Copy link

@marcbaechinger do we have some option to override MediaSession::onTimelineChanged? Or perhaps there is some other workaround?

@DenysLoboda
Copy link

In fact, when using the support library, this behavior is also observed. I managed to get the playlist off by overriding MediaMetadataProvider and assuming QueueNavigator is not set. Are there any equivalents for this for media3?

copybara-service bot pushed a commit that referenced this issue Oct 16, 2023
Android Auto shows a queue button when the queue is not empty.
Apps were able to remove this queue button with the legacy API
by not setting the queue of the session.

After this change, removing `COMMAND_GET_TIMELINE` from the commands
of the media notification controller or the session player sets the
queue in the platform session to null.

#minor-release
Issue: #339
PiperOrigin-RevId: 573813558
@marcbaechinger
Copy link
Contributor

With the commit above that landed in the main branch and will be released with 1.2.0, an app can now remove the queue button in Android Auto/Automotive OS by removing COMMNAD_GET_TIMELINE:

override fun onConnect(
  session: MediaSession,
  controller: MediaSession.ControllerInfo
): MediaSession.ConnectionResult {
  if (session.isMediaNotificationController(controller)) {
    val playerCommands =
      Player.Commands.Builder().addAllCommands().remove(COMMAND_GET_TIMELINE).build()
    return MediaSession.ConnectionResult.AcceptedResultBuilder(session)
      .setAvailablePlayerCommands(playerCommands)
      .build()
  }
}

With this the queue is not set on the framework session and the button is not displayed y Auto.

An app can change this setting during runtime like for instance when the user adds a playlist instead a radio stream and an app want to alternate between the two behaviors:

session.mediaNotificationControllerInfo?.let {
  val playerCommands = Player.Commands.Builder().addAllCommands()
  val sessionCommands = getSessionCommandsIncludingCustomCommands() // provided by app
  session.setAvailableCommands(it, sessionCommands, playerCommands)
}

An app can do this even when the app wants to support the System UI notification in parallel. COMMAND_GET_TIMELINE is not required for supporting the System UI media notification.

@marcbaechinger
Copy link
Contributor

marcbaechinger commented Oct 16, 2023

@Guardiannw Sorry for the wait and thanks for your report!

@DenysLoboda

when using the support library, this behavior is also observed.
Are there any equivalents for this for media3?

You can remove COMMAND_GET_TIMELINE as explained above.

do we have some option to override MediaSession::onTimelineChanged?

Na, there is no such method. I think with the option added now, you can now do what you want by API.

I'm closing as the question is answered and we now have an API for this. Please open a new issue in case you find issues with the provided solution.

rohitjoins pushed a commit that referenced this issue Oct 23, 2023
Android Auto shows a queue button when the queue is not empty.
Apps were able to remove this queue button with the legacy API
by not setting the queue of the session.

After this change, removing `COMMAND_GET_TIMELINE` from the commands
of the media notification controller or the session player sets the
queue in the platform session to null.

#minor-release
Issue: #339
PiperOrigin-RevId: 573813558
(cherry picked from commit f53e1bc)
@androidx androidx locked and limited conversation to collaborators Dec 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants