Skip to content

Implement media control#287

Merged
Stypox merged 13 commits intoStypox:masterfrom
papjul:media_control
Feb 21, 2025
Merged

Implement media control#287
Stypox merged 13 commits intoStypox:masterfrom
papjul:media_control

Conversation

@papjul
Copy link
Contributor

@papjul papjul commented Feb 19, 2025

Fix #252


next:
- (joue|jouer|jouez|mais|mets|mettez|mettre)? (la|le)? chanson|média|piste suivant<e?>
- (joue|jouer|jouez|mais|mets|mettez|mettre|passe à|passer à|passez à)? (la|le)? chanson|média|piste|musique|audio|film|stream suivant<e?>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The | binds stronger than word boundaries, so you should do (passe à)|(passer à)|(passez à) instead


pause:
- mais|mets|mettez|mettre (la|le chanson|média|piste sur pause)|(sur pause la|le chanson|média|piste)
- mais|mets|mettez|mettre ((la|le)? chanson|média|piste sur pause)|(sur pause (la|le)? chanson|média|piste|musique|audio|film|stream)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't necessarily need the parenthesis in (la|le)?, but this is not important

@Stypox
Copy link
Owner

Stypox commented Feb 21, 2025

Thank you! I made some changes to the permission system so it's nicer to use, and added some documentation. I would suggest writing a bit more documentation next time, e.g. like I did in 7e5317d or 02727ac :-)

@Stypox Stypox merged commit 81c7aa5 into Stypox:master Feb 21, 2025
@papjul
Copy link
Contributor Author

papjul commented Feb 21, 2025

Thank you too for the updates and the quick merging :)
I will think about it next time ;)

@Stypox
Copy link
Owner

Stypox commented Apr 4, 2025

Apparently this does not work, see the documentation for getActiveSessions:

This requires the Manifest.permission.MEDIA_CONTENT_CONTROL permission be held by the calling app. You may also retrieve this list if your app is an enabled notification listener using the NotificationListenerService APIs, in which case you must pass the ComponentName of your enabled listener.

However the MEDIA_CONTENT_CONTROL permission is only available to system apps (and apparently also debug apps, because while I was testing I didn't get any error whatsoever!). So we may want to try the alternative suggested above, however it seems overly complicated to use a listener service running in the background just to get a list of media apps... Gotta love Android 😫

@Stypox
Copy link
Owner

Stypox commented Apr 4, 2025

Fixed in 4909bbb, apparently you can use AudioManager and that doesn't require any permission. Thanks to how well documented Android is, I only found out about this method in a kind-of unrelated StackOverflow question https://stackoverflow.com/q/67979372 . I tested on API 36 emulated, API 22 emulated and API 34 on-device and it seems to work.

@papjul
Copy link
Contributor Author

papjul commented Apr 4, 2025

Wow, well done!
I'm sorry I didn't know about this limit

@Stypox
Copy link
Owner

Stypox commented Apr 4, 2025

Don't worry, I didn't know either and it worked without issues when I tested the debug build

@papjul papjul deleted the media_control branch April 6, 2025 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Control the current media player background notification

2 participants