-
-
Notifications
You must be signed in to change notification settings - Fork 965
Add native Android media controls for HA media_player entities #6626
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
Open
FletcherD
wants to merge
118
commits into
home-assistant:main
Choose a base branch
from
FletcherD:feature/native-media-controls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 48 commits
Commits
Show all changes
118 commits
Select commit
Hold shift + click to select a range
75e9d8b
Add native Android media controls for HA media_player entities
FletcherD 20bb0b1
1. Dispatchers.Main → Dispatchers.Default in service scope
FletcherD 3b3178d
Add volume control to native media controls
FletcherD ba45502
Decouple session logic from HaMediaSessionService into HaMediaSession
FletcherD 45a112b
Stop media session service when its configured server is deleted
FletcherD 133c278
Support multiple media_player entities as native media controls
FletcherD 3bd574e
add COMMAND_SET_DEVICE_VOLUME and COMMAND_ADJUST_DEVICE_VOLUME back a…
FletcherD c83de10
Put the player into STATE_BUFFERING on disconnect when the WebSocket …
FletcherD 7028496
Address PR review feedback on media session code
FletcherD 4ee48ed
Use URL for artwork path
FletcherD 2b1cbf2
Refactor Media Control settings UI to use reorderable picker similar …
FletcherD bbad9c2
Refactor to avoid ComposeUnstableCollections issues, remove stale lin…
FletcherD f484849
Store media control configuration in the database instead of PrefsRep…
FletcherD c434c30
Fix crash when adding media control entity; Fix artwork disappearing …
FletcherD e75df17
Fetch media information and artwork immediately on startObservingState
FletcherD 16805bd
Remove Save and Clear All buttons from media control settings page, s…
FletcherD eea9e85
Minor cleanup
FletcherD cf2db98
Fix multi-entity session routing; add @AssistedInject and unit tests
FletcherD f11db4c
ktlint fixes
FletcherD 2b3209d
Reactively manage sessions via observeConfiguredEntities() flow
FletcherD 52ba3b7
Fix media controls not appearing on cold start
FletcherD b14c1e5
Fix media controls not appearing on cold start on V2 frontend
FletcherD 1ad0c4e
Expose stop, mute, shuffle, and repeat functions to media controls
FletcherD 5abd769
Merge branch 'main' into feature/native-media-controls
FletcherD 8375610
Expose more metadata fields from media player entity
FletcherD 045ede1
Make media controls settings page more consistent with other settings
FletcherD 1290d3e
Remove setContentBufferedPositionMs() call which is useless
FletcherD d36ba76
Tapping media controls notification body opens the media player entit…
FletcherD 5563c41
Address mechanical PR review comments from TimoPtr
FletcherD c5089c0
Address coroutine architecture PR review comments
FletcherD b65ddb0
Split up HaRemoteMediaPlayer.kt getState(); use entityFriendlyName in…
FletcherD 23c5d38
→ use ; Remove the four fields.
FletcherD 8702016
Address MediaControlSettings PR review comments
FletcherD 70080ba
Fix showing entity name instead of track title; Add small app icon to…
FletcherD 4a4f113
When disconnected, retry only once when opening app instead of in a l…
FletcherD ebe2801
Simplify startObservingState by moving initial fetch into observeEnti…
FletcherD 9a2cec1
FrontendViewModel.kt: Removed appContext: Context, mediaControlReposi…
FletcherD 09ac27e
ktlint fix
FletcherD 06172da
loadArtworkAndUpdatePlayer now uses state.entityPictureUrl as the cac…
FletcherD fb0612c
Don't include .size() when requesting artwork image
FletcherD 612a1f8
Remove ServerRegistries in MediaControlSettingsViewModel.kt; Remove '…
FletcherD 5867fe5
HaMediaSessionTest.kt: Remove Thread.sleep
FletcherD b6af049
HaMediaSessionServiceTest.kt: Don't call reconcileSessions() directly…
FletcherD 5c1251a
Remove fake 3-item playlist from HaRemoteMediaPlayer
FletcherD 2a28179
Remove automotive and Meya Quest support for media controls
FletcherD 0d1bd25
Remove Meta Quest support for media controls
FletcherD b7d9e0b
Add screenshot tests for MediaControlSettingsScreen
FletcherD 1c9b63f
Merge origin/main into feature/native-media-controls
FletcherD c3641e6
Remove the reconnect() call from onStartCommand so we don't cancel We…
FletcherD 08b8d6f
Remove retry loop from startObservingState()
FletcherD 4278fb2
Refactor HaMediaSession.kt: Remove scope creation from this class. In…
FletcherD 26a8a83
Code clarity in HaRemoteMediaPlayer.kt
FletcherD 6b823b1
HaRemoteMediaPlayer.kt
FletcherD 7de40bb
Address PR review comments (batch 1)
FletcherD 9d48643
HaMediaSessionService: Document why onTaskRemoved skips stopSelf when…
FletcherD eda99bf
HaMediaSessionService: Remove repository param from startIfConfigured
FletcherD 5766948
WebViewActivity: Revert unrelated deep-link handling change
FletcherD c491d11
MediaControlSettings: Move HATheme from Screen composable into Fragme…
FletcherD 1f607e8
HaMediaSessionServiceTest: Remove redundant unmockkAll() — instance m…
FletcherD 3b85483
MediaControlConfig: Rename position column to index
FletcherD 5d53fe6
Revert changes to ServerSettingsPresenterImpl.kt; Revert log message …
FletcherD 20757c4
Fix crash when removing/readding entity in settings
FletcherD e2c2120
Workaround for notification disappearing after adding two entities an…
FletcherD fd69a5d
Refactor to fix multiple entitites: Build MediaStyle notifications ou…
FletcherD a695d13
Set notification when playing so it can't be swiped away (dismissibl…
FletcherD e75dea8
Remove entity reordering from media controls settings screen
FletcherD 1b38f33
Fix MediaControlRepositoryImplTest tests
FletcherD 3575cfe
Fix subtitle in media control settings entity row; Fix defunct notifi…
FletcherD a3ffa0a
Improve media control settings screen: Don't show anything until load…
FletcherD 0ad3588
Make activeSessions, reconcileSessions, and startObservingEntities pr…
FletcherD 82895ff
MediaControlSettingsViewModel.kt: inject the Default dispatcher into …
FletcherD 99b6b10
Media controls tests: Clean up properly after tests
FletcherD 3c65412
Update screenshot tests for media control settings changes and regene…
FletcherD 1eda4e4
Merge origin/main into feature/native-media-controls
FletcherD ad135f5
All `handle*()` methods return a pending `SettableFuture<Void>` (stor…
FletcherD e0e43d6
Cleanup test structure
FletcherD 3b32629
Merge origin/main into feature/native-media-controls
FletcherD adee5e9
Remove unnecessary SDK_INT version check
FletcherD cb0f9d5
Merge branch 'main' into feature/native-media-controls
FletcherD 304ed6c
Move media control service start to LaunchActivity
FletcherD 30073b4
Use @ApplicationContext in HaMediaSession constructor
FletcherD 275b4ec
Encapsulate MediaSession inside HaMediaSession, expose id and notific…
FletcherD c4b1784
Refactor CommandCallback to return Job, tie ListenableFuture to corou…
FletcherD c222e81
Remove actionScope field, pass scope to getCommandCallback, make call…
FletcherD d3794a2
Add FailFast guard in HaMediaSession.observe() for double-call
FletcherD 535cb96
Remove verbose log in observe(), make startObservingState private
FletcherD 9baa5b1
Use LaunchActivity for media notification tap intent
FletcherD c6c4314
Simplify loadArtworkAndUpdatePlayer in HaMediaSession
FletcherD 486a859
Fix log message in resolveArtworkUrl to reference server ID
FletcherD 71bb517
Split reconcileSessions into smaller helper functions
FletcherD f5a47c4
Remove unnecessary onStartCommand override in HaMediaSessionService
FletcherD 4f5be54
Confine activeSessions map access to Main thread
FletcherD 6f6fa04
Pre-scale album art to notification icon size to avoid main thread do…
FletcherD fddbcd1
Revert "Encapsulate MediaSession inside HaMediaSession, expose id and…
FletcherD 623bb57
Restore tests: observe() stays alive after flow ends, restarts on com…
FletcherD eaf71d6
Encapsulate MediaSession inside HaMediaSession, expose id and notific…
FletcherD 7c4b248
Unify session ID format with map key; use key string in promoteForegr…
FletcherD f6cd168
Merge remote-tracking branch 'fork/feature/native-media-controls' int…
FletcherD b416ec7
Fix HaMediaSessionService constructor and test
FletcherD 6336c81
add commandScope in HaMediaSession so thrown exceptions are handled g…
FletcherD 168fd9c
remove restartObservationIfNeeded; remove unregisterFrom
FletcherD 09e456d
Add test to verify HaMediaSessionService.start is called in LaunchAct…
FletcherD cf42a8f
Address trivial PR review comments from @TimoPtr
FletcherD e85b81a
Address more PR review comments from @TimoPtr
FletcherD f4ff7c5
Address threading PR review comments (threads 8, 9, 10)
FletcherD ea35aed
Address PR thread 6: move startObservingState after player creation
FletcherD 9727ee4
Return failed future for unsupported commands in handleCommand
FletcherD aa94487
Fix HaMediaSession coroutineScope hanging on natural flow completion
FletcherD f608103
Clarify comment on MediaPlaybackState.Off -> STATE_IDLE mapping
FletcherD 86d0420
Address trivial PR review comments (threads 33, 35, 48, 51)
FletcherD 5c19e07
Address PR review comments (threads 29, 30, 32, 36, 52)
FletcherD 2b399b3
Pre-scale notification album art bitmap on IO to fix StrictMode viola…
FletcherD 2e620a9
Address PR review comments (threads 34, 39, 40, 41)
FletcherD 32ff7da
Address PR review comments (threads 42–47): refactor MediaControlSett…
FletcherD 7068ddd
Remove index column from MediaControlConfig (thread 53)
FletcherD a8c57a1
Fix seek-bar regression after media commands by completing pendingCom…
FletcherD 4fc1f1b
Update screenshot reference images for MediaControlSettingsScreen
FletcherD 38935d8
Merge origin/main into feature/native-media-controls
FletcherD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ain/kotlin/io/homeassistant/companion/android/mediacontrol/HaMediaNotificationProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package io.homeassistant.companion.android.mediacontrol | ||
|
|
||
| import android.content.Context | ||
| import androidx.core.app.NotificationCompat | ||
| import androidx.media3.common.util.UnstableApi | ||
| import androidx.media3.session.CommandButton | ||
| import androidx.media3.session.DefaultMediaNotificationProvider | ||
| import androidx.media3.session.MediaNotification | ||
| import androidx.media3.session.MediaSession | ||
| import com.google.common.collect.ImmutableList | ||
| import io.homeassistant.companion.android.common.R as commonR | ||
|
|
||
| /** | ||
| * Extends [DefaultMediaNotificationProvider] to display the Home Assistant notification icon | ||
| * and the media player entity's friendly name as the notification sub-text. | ||
| * | ||
| * @param sessionEntityName Maps a session ID to the friendly name of its media_player entity. | ||
| * May return null if the entity name is not yet known. | ||
| */ | ||
| @UnstableApi | ||
| class HaMediaNotificationProvider(context: Context, private val sessionEntityName: (sessionId: String) -> String?) : | ||
|
FletcherD marked this conversation as resolved.
Outdated
|
||
| DefaultMediaNotificationProvider(context) { | ||
|
|
||
| init { | ||
| setSmallIcon(commonR.drawable.ic_stat_ic_notification) | ||
| } | ||
|
|
||
| override fun addNotificationActions( | ||
| mediaSession: MediaSession, | ||
| mediaButtons: ImmutableList<CommandButton>, | ||
| builder: NotificationCompat.Builder, | ||
| actionFactory: MediaNotification.ActionFactory, | ||
| ): IntArray { | ||
| sessionEntityName(mediaSession.id)?.let { builder.setSubText(it) } | ||
| return super.addNotificationActions(mediaSession, mediaButtons, builder, actionFactory) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.