You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Update MediaSessionManager to return priority order of sessions as shown by System UI #171
In Media3 there is no class/mechanism equivalent of a MediaSessionManager?
If I want my app to control the media session that another app is running, the only way is to convert android.media.session.MediaSession.Token (obtained by the system MediaSessionManager) to MediaSessionCompat.Token then to convert it again to androidx.media3.session.Token? Or did I miss something?
Would it help to have a similar method converting android.media.session.MediaSession.Token to a media3 token?
Not sure if relevant to your use case, but it's also possible to directly query all existing media3 sessions associated with a service using this method:
Note that this list doesn't include sessions that are not associated to a service (MediaSessionService or MediaLibraryService or MediaBrowserServiceCompat).
If the idea of the media3 library is to progressively phase out the need of the other older media support library, I think it would be good to have a method to directly convert android.media.session.MediaSession.Token to a media3 session token. This way there wouldn't be a need to have a direct dependency to both libraries from our app.
I saw the getAllServiceTokens method but it's not clear to me how to distinguish which token is the one currently active, and like you mentioned we might be missing some sessions in that case. We are also running into SecurityExceptions when trying to create MediaControllers from these tokens.
To explain better our use case, we have a bluetooth companion app, and our users are able to control music played on the Android phone, directly from the watches. Our Android app forwards the media session information from Android to the watches and the inverse is true for the commands (play/pause/skip etc.). We aim to have an implementation that works with as many Android music/media applications as possible.
I think it would be good to have a method to directly convert android.media.session.MediaSession.Token to a media3 session token.
Agree, I'll convert this to an enhancement.
I saw the getAllServiceTokens method but it's not clear to me how to distinguish which token is the one currently active, and like you mentioned we might be missing some sessions in that case.
That's interesting. I wonder if we need the equivalent of MediaSessionManager.getActiveSessions() that returns an ordered list with the most relevant session listed first. @marcbaechinger What's your take on this?
We are also running into SecurityExceptions when trying to create MediaControllers from these tokens.
Isn't this expected if you don't have permission to access these sessions?
changed the title [-]How to correctly acquire ongoing media session token from another app?[/-][+]Add helper method to convert platform MediaSession.Token to media3 session Token[/+]on Sep 21, 2022
We are also running into SecurityExceptions when trying to create MediaControllers from these tokens.
Isn't` this expected if you don't have permission to access these sessions?
We have permissions to access notifications and we can trigger theirs actions. Controlling any app through the session tokens retrieved from the MediaSessionManager seems to be working fine.
There is a helper method to convert a platform token to a Media3 token and we now have a MediaSessionManager class in Media3 to provide direct access to Media3 tokens of all sessions (assuming your app has the right permissions).
I'll leave this issue open to track the idea of returning an ordered list sorted by the priority SysUI applies to sessions for a more consistent view on the data.
changed the title [-]Add helper method to convert platform MediaSession.Token to media3 session Token[/-][+]Update MediaSessionManager to return priority order of sessions as shown by System UI[/+]on Jun 30, 2026
Activity
tonihei commentedon Sep 21, 2022
This is more of less correct when going from a platform
android.media.session.MediaSession.Tokento a media3 session token.There is already a method to convert the
MediaSessionCompat.Tokento the media3 token:media/libraries/session/src/main/java/androidx/media3/session/SessionToken.java
Line 260 in 5047581
Would it help to have a similar method converting
android.media.session.MediaSession.Tokento a media3 token?Not sure if relevant to your use case, but it's also possible to directly query all existing media3 sessions associated with a service using this method:
media/libraries/session/src/main/java/androidx/media3/session/SessionToken.java
Line 326 in 5047581
Note that this list doesn't include sessions that are not associated to a service (
MediaSessionServiceorMediaLibraryServiceorMediaBrowserServiceCompat).entibaldi commentedon Sep 21, 2022
If the idea of the media3 library is to progressively phase out the need of the other older media support library, I think it would be good to have a method to directly convert
android.media.session.MediaSession.Tokento a media3 session token. This way there wouldn't be a need to have a direct dependency to both libraries from our app.I saw the
getAllServiceTokensmethod but it's not clear to me how to distinguish which token is the one currently active, and like you mentioned we might be missing some sessions in that case. We are also running into SecurityExceptions when trying to create MediaControllers from these tokens.To explain better our use case, we have a bluetooth companion app, and our users are able to control music played on the Android phone, directly from the watches. Our Android app forwards the media session information from Android to the watches and the inverse is true for the commands (play/pause/skip etc.). We aim to have an implementation that works with as many Android music/media applications as possible.
tonihei commentedon Sep 21, 2022
Agree, I'll convert this to an enhancement.
That's interesting. I wonder if we need the equivalent of
MediaSessionManager.getActiveSessions()that returns an ordered list with the most relevant session listed first. @marcbaechinger What's your take on this?Isn't this expected if you don't have permission to access these sessions?
[-]How to correctly acquire ongoing media session token from another app?[/-][+]Add helper method to convert platform MediaSession.Token to media3 session Token[/+]entibaldi commentedon Sep 21, 2022
We have permissions to access notifications and we can trigger theirs actions. Controlling any app through the session tokens retrieved from the
MediaSessionManagerseems to be working fine.Add helper method to convert platform session token to Media3 token
Add helper method to convert platform session token to Media3 token
Chore/migrate media 1.0.2 (#10)
Merge pull request androidx#171 from Guovin/master
tonihei commentedon Jun 30, 2026
There is a helper method to convert a platform token to a Media3 token and we now have a MediaSessionManager class in Media3 to provide direct access to Media3 tokens of all sessions (assuming your app has the right permissions).
I'll leave this issue open to track the idea of returning an ordered list sorted by the priority SysUI applies to sessions for a more consistent view on the data.
[-]Add helper method to convert platform MediaSession.Token to media3 session Token[/-][+]Update MediaSessionManager to return priority order of sessions as shown by System UI[/+]