Add native Android media controls for HA media_player entities#6622
Add native Android media controls for HA media_player entities#6622FletcherD wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Hi @FletcherD
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
There was a problem hiding this comment.
Pull request overview
Adds a new feature that exposes a selected Home Assistant media_player entity as native Android media controls (MediaSession) and provides a settings UI to configure which entity is exposed.
Changes:
- Introduces
MediaControlRepository+ state model and preference storage for the configured server/entity - Adds a MediaSessionService (
HaMediaSessionService) + remotePlayeradapter to bridge Android transport controls to HA service calls - Adds settings entry + Compose settings screen, plus unit/Robolectric tests and changelog entry
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| common/src/test/kotlin/io/homeassistant/companion/android/common/data/mediacontrol/MediaControlRepositoryImplTest.kt | Unit tests for repository state observation and mapping |
| common/src/main/res/values/strings.xml | Adds user-facing strings for media controls settings |
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/prefs/PrefsRepositoryImpl.kt | Persists/clears configured media control server/entity preferences |
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/prefs/PrefsRepository.kt | Adds preference APIs for media control configuration |
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/mediacontrol/MediaControlState.kt | Defines media control state + playback state model |
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/mediacontrol/MediaControlRepositoryImpl.kt | Observes entity state via WebSocket and maps to MediaControlState |
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/mediacontrol/MediaControlRepository.kt | Repository contract for state/config management |
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/mediacontrol/MediaControlModule.kt | Hilt binding for the repository implementation |
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/integration/Entity.kt | Adds media_player supported feature bitmasks and media metadata helpers |
| automotive/src/main/AndroidManifest.xml | Declares MediaSessionService + FGS media playback permission |
| automotive/lint-baseline.xml | Updates baseline (including new Compose lint entries) |
| app/src/test/kotlin/io/homeassistant/companion/android/settings/mediacontrol/MediaControlSettingsViewModelTest.kt | Unit tests for settings ViewModel interactions |
| app/src/test/kotlin/io/homeassistant/companion/android/mediacontrol/HaRemoteMediaPlayerTest.kt | Robolectric tests for player state/commands mapping |
| app/src/main/res/xml/preferences.xml | Adds settings category + entry point for media controls |
| app/src/main/res/xml/changelog_master.xml | Adds changelog entry for the new feature |
| app/src/main/res/drawable/ic_play_circle_outline.xml | Adds icon for the settings entry |
| app/src/main/kotlin/io/homeassistant/companion/android/settings/mediacontrol/views/MediaControlSettingsView.kt | Compose UI for selecting server/entity and saving/clearing |
| app/src/main/kotlin/io/homeassistant/companion/android/settings/mediacontrol/MediaControlSettingsViewModel.kt | Loads servers/entities/registries and starts/stops the service on save/clear |
| app/src/main/kotlin/io/homeassistant/companion/android/settings/mediacontrol/MediaControlSettingsFragment.kt | Hosts the Compose settings screen in a Fragment |
| app/src/main/kotlin/io/homeassistant/companion/android/settings/SettingsFragment.kt | Wires the new preference entry to the settings fragment navigation |
| app/src/main/kotlin/io/homeassistant/companion/android/mediacontrol/HaRemoteMediaPlayer.kt | SimpleBasePlayer adapter translating Android commands to callbacks |
| app/src/main/kotlin/io/homeassistant/companion/android/mediacontrol/HaMediaSessionService.kt | MediaSessionService observing HA state, loading artwork, and calling HA actions |
| app/src/main/AndroidManifest.xml | Declares MediaSessionService + FGS media playback permission |
| app/lint-baseline.xml | Updates baseline (including new Compose lint entries) |
There was a problem hiding this comment.
ktlint found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
9a01008 to
27e5469
Compare
27e5469 to
4504277
Compare
4504277 to
43f0798
Compare
43f0798 to
51081e1
Compare
2a44795 to
4e8028a
Compare
4e8028a to
79d3521
Compare
1f6fe7c to
f0cc831
Compare
f0cc831 to
5098fb6
Compare
5098fb6 to
a4916c8
Compare
a4916c8 to
c9a2d04
Compare
|
Closing to recreate with clean history. |
Summary
I wanted to be able to control a media player entity natively on Android without having to open the app or navigate to a widget. So this feature exposes a Home Assistant
media_playerentity as native Android Media Controls (described here) in the notification shade, the same UI used by other media players on Android.The media controls show the currently playing track info and play position with album art. Prev/next track, play/pause and seek controls work and are forwarded to the media_player entity (if the entity supports them).
A new "Media controls" setting is added under "Companion app" to choose which media_player entity to expose in the media controls, if any. One entity at a time can be selected.
Unit tests are added to test playback state mapping, state flow, settings and everything else I could think of.
Checklist
Screenshots
Link to pull request in documentation repositories
User Documentation PR: home-assistant/companion.home-assistant#1304