Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
translate ▾

Modern-Apps.git / music / AGENTS.md

AGENTS.md10.0 KiBRenderedCodeRaw
1# AGENTS.md — music/ (':music')
2
3> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `music/` + allowed shared modules. Do not root-scan.
4
5_Install: ./install music (dev by default)._
6- Gradle: :music / dir: music/
7- Package roots present: ui, data, platform, intents, service, sync
8- Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt, Navigation.kt, ui/WearMainActivity.kt
9- Deps: :library:room, :library:image, :sdk:cast, :library:media, :library:wearlink, :library:log, Wear Compose (material + foundation)
10- Metadata: metadata_data/music.md (present)
11- Rust: no / screenshotTest: yes
12
13## Overview
14**Purpose:** Offline M3Y music player — local library by song/album/artist/playlist, synced lyrics from file tags, Cast to TV, Android Auto. No network permission at all.
15**Key features:**
16- Library scan into Room (`Music`/`Album`/`Artist`/`Playlist`) with `SyncWorker`; now-playing + queue + shuffle, wide-layout player
17- Embedded + synced lyrics views; playlist CRUD as dialog routes (`CreatePlaylistDialog`, `DeletePlaylistDialog`, `RenamePlaylistDialog`, `AddToPlaylistDialog` with `DialogPage()` metadata and stateless contents under `ui/dialogs/`); audio-preview + play/search assistant intents + capped assistant reads (now-playing summary, playlist names/counts ≤10, playlist track titles ≤10, search capped at 20 hits)
18- Playback in `service/PlaybackService` (local) / `CastingPlayer` (remote via `:sdk:cast`); `MusicLibraryTree` exposes the Auto tree
19**Architecture / data-flow:** `ui/` tabs + now-playing → `platform/MusicViewModel` (+ `MusicUiContract`) + `platform/PlaybackManager` → `data/MusicRepository` over Room + `service/PlaybackService`; `platform/CastPlayback` + `service/CastQueue` take over when casting.
20**Entry points + reading order:** `Route` → `MainActivity.kt` → `Navigation.kt` → `ui/MusicTabsScreen.kt` → `platform/PlaybackManager.kt` → `service/PlaybackService.kt` → `data/MusicRepository.kt`.
21**Gotchas:**
22- Playback state lives in the service, not the ViewModel — UI binds, never owns. The watch UI is bound the same way: it renders phone-reported state from `data/WearMusicStore` and sends ops, never owns playback.
23- Cast and local are separate player paths sharing one queue model; test handoff, not just each side
24- While casting, the TV plays single resources and knows no repeat/shuffle: `CastQueue` honours the phone's repeat mode on a TV `ended` (repeat-one re-offers the same track, repeat-all wraps via the local queue, shuffle order comes from the local timeline)
25
26## One APK, two form factors (phone + watch)
27This module is the single Music APK for phones and watches: same
28`applicationId = "com.vayunmathur.music"` and signing on both, as the
29WearLink handshake requires. The manifest deliberately declares no
30`android.hardware.type.watch` feature (required=true would block
31phones; required=false is disallowed for this feature), plus
32touchscreen not-required and
33`com.google.android.wearable.standalone=false`; distribution is
34sideload/F-Droid, not Play's watch channel, so the APK installs on
35phones and watches alike. `platform/FormFactor.kt` reads
36`PackageManager.FEATURE_WATCH` at runtime: `MainActivity` (the sole
37launcher entry) forwards watches to `ui/WearMainActivity` before any
38phone state loads; phones get the tab UI. The phone-only entry points
39gate on the same signal: `sync/WearMusicSync.start` (phone conduit
40client node) is a no-op on a watch, and `service/PlaybackService` creates no
41player or session on a watch.
42
43## Wear sync (Watch conduit client)
44**Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.music.WearMusicProtocol`; the golden-JSON tests in this module pin the shared code's wire format.
45- Page snapshots: conduit data item (`/music/page`, phone -> watch), requested by message (`/music/page-request`, watch -> phone)
46- Now-playing: conduit data item (`/music/playback`, phone -> watch)
47- Watch state: conduit data item (`/music/watch-state`, watch -> phone)
48- Playback/library ops: conduit message (`/music/op`, watch -> phone)
49- Search: conduit message (`/music/search-request`, watch -> phone)
50- **Transport: Watch conduit client** — phone side `sync/WearMusicSync.kt` and watch side `sync/WearLinkBridge.kt` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `music`); this app owns no RFCOMM link and holds no Bluetooth permission for this channel, so neither entry activity prompts for Bluetooth. With the Watch app absent the node reports `NotInstalled`/`Unavailable` and the sync stays idle; playback state republishes on conduit `Connected`, and pending watch ops resend on `Connected`. `FormFactor` picks the side at runtime, so only one of the two nodes runs on a given device.
51
52## Watch experience (in this module)
53- `ui/WearMainActivity` routes `ui/WearRoute` (home / albums / artists / playlists / now playing / queue / search / add-to-playlist / settings) over the phone's pages, rendered from cached page snapshots + streamed playback state in `data/WearMusicStore` (`wear-music-pages.json`), so visited pages work offline.
54- The phone owns the catalog and is the only audio player: the watch stores no music files and no whole catalog, and every playback action is an op executed by the phone's playback service; the watch UI reflects the phone-reported state and never claims an unconfirmed result.
55- Watch listing screenshots are the `group = "wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by `:music:metadata` into `metadata_data/photos/music/wear/`; phone shots use the `phone` bucket.
56
57## Key files
58### Root — entry + navigation
59- com/vayunmathur/music/MainActivity.kt
60- com/vayunmathur/music/Navigation.kt
61- com/vayunmathur/music/Route.kt
62### data/ — Room library
63- com/vayunmathur/music/data/MusicDatabase.kt
64- com/vayunmathur/music/data/MusicRepository.kt
65- com/vayunmathur/music/data/Music.kt
66- com/vayunmathur/music/data/Album.kt
67- com/vayunmathur/music/data/Artist.kt
68- com/vayunmathur/music/data/Playlist.kt
69### platform/ — ViewModel, playback glue, lyrics
70- com/vayunmathur/music/platform/MusicViewModel.kt
71- com/vayunmathur/music/platform/MusicUiContract.kt
72- com/vayunmathur/music/platform/PlaybackManager.kt
73- com/vayunmathur/music/platform/CastPlayback.kt
74- com/vayunmathur/music/platform/Lyrics.kt
75- com/vayunmathur/music/platform/EmbeddedLyrics.kt
76- com/vayunmathur/music/platform/SyncWorker.kt
77- com/vayunmathur/music/platform/Util.kt
78- com/vayunmathur/music/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`)
79### service/ — playback + Auto tree + cast queue
80- com/vayunmathur/music/service/PlaybackService.kt
81- com/vayunmathur/music/service/MusicLibraryTree.kt
82- com/vayunmathur/music/service/CastingPlayer.kt
83- com/vayunmathur/music/service/CastQueue.kt
84### sync/ — wear companion sync (both sides, one APK)
85- com/vayunmathur/music/sync/WearMusicSync.kt — phone conduit client node; page publish, playback stream, op execution
86- com/vayunmathur/music/sync/WearLinkBridge.kt — watch conduit client node; page/playback receive, op send, watch-state publish
87### Watch experience (ui/ + data/)
88- com/vayunmathur/music/ui/WearMainActivity.kt — watch entry
89- com/vayunmathur/music/ui/WearRoute.kt, WearMusicRoot.kt, WearHomeScreen.kt, WearPageLoader.kt, WearNowPlayingScreen.kt, WearTrackListScreen.kt, WearAlbumListScreen.kt, WearArtistListScreen.kt, WearPlaylistListScreen.kt, WearQueueScreen.kt, WearSearchScreen.kt, WearAddToPlaylistScreen.kt, WearSettingsScreen.kt
90- com/vayunmathur/music/data/WearMusicStore.kt — visited page snapshots + latest playback state (`wear-music-pages.json`)
91### intents/ — assistant playback IPC
92- com/vayunmathur/music/intents/PlayIntent.kt
93- com/vayunmathur/music/intents/SearchIntent.kt
94- com/vayunmathur/music/intents/NowPlayingIntent.kt — `music_get_now_playing` (`NowPlayingData`)
95- com/vayunmathur/music/intents/GetPlaylistsIntent.kt — `music_get_playlists` (names/counts, cap 10)
96- com/vayunmathur/music/intents/GetPlaylistTracksIntent.kt — `music_get_playlist_tracks` (titles, cap 10)
97- com/vayunmathur/music/intents/AudioPreviewActivity.kt
98### ui/ + ui/components/ + ui/dialogs/ — library, player, playlists
99- com/vayunmathur/music/ui/MusicTabsScreen.kt
100- com/vayunmathur/music/ui/HomeScreen.kt
101- com/vayunmathur/music/ui/SongsScreen.kt
102- com/vayunmathur/music/ui/SongScreen.kt
103- com/vayunmathur/music/ui/AlbumScreen.kt
104- com/vayunmathur/music/ui/AlbumDetailScreen.kt
105- com/vayunmathur/music/ui/AlbumDetailContent.kt
106- com/vayunmathur/music/ui/ArtistScreen.kt
107- com/vayunmathur/music/ui/ArtistDetailScreen.kt
108- com/vayunmathur/music/ui/PlaylistScreen.kt
109- com/vayunmathur/music/ui/PlaylistDetailScreen.kt
110- com/vayunmathur/music/ui/NowPlayingScreen.kt
111- com/vayunmathur/music/ui/NowPlayingColumn.kt
112- com/vayunmathur/music/ui/NowPlayingQueue.kt
113- com/vayunmathur/music/ui/NowPlayingWideLayout.kt
114- com/vayunmathur/music/ui/LyricsView.kt
115- com/vayunmathur/music/ui/components/NowPlayingBar.kt
116- com/vayunmathur/music/ui/components/PlayingBottomBar.kt
117- com/vayunmathur/music/ui/components/PlayShuffleRow.kt
118- com/vayunmathur/music/ui/components/ShufflePlayFab.kt
119- com/vayunmathur/music/ui/components/NewPlaylistFab.kt
120- com/vayunmathur/music/ui/components/AddToPlaylistButton.kt
121- com/vayunmathur/music/ui/components/MusicTabsBar.kt
122- com/vayunmathur/music/ui/components/TrackListItem.kt
123- com/vayunmathur/music/ui/AlbumsContent.kt
124- com/vayunmathur/music/ui/ArtistsContent.kt
125- com/vayunmathur/music/ui/PlaylistsContent.kt
126- com/vayunmathur/music/ui/AlbumDetailContent.kt
127- com/vayunmathur/music/ui/ArtistDetailContent.kt
128- com/vayunmathur/music/ui/PlaylistDetailContent.kt
129- com/vayunmathur/music/ui/dialogs/AddToPlaylistDialog.kt
130- com/vayunmathur/music/ui/dialogs/AddToPlaylistDialogContent.kt
131- com/vayunmathur/music/ui/dialogs/CreatePlaylistDialog.kt
132- com/vayunmathur/music/ui/dialogs/DeletePlaylistDialogContent.kt
133- com/vayunmathur/music/ui/dialogs/RenamePlaylistDialogContent.kt
134
135## Verify (this module only)
136```
137./gradlew :music:compileDevKotlin
138./gradlew :music:lint :music:lintVitalRelease
139./gradlew :music:testDevUnitTest
140./gradlew :music:checkMetadata
141```