Repository navigation
Conversation
…ing (#271) * feat(app): add LAN companion remote, handoff, and cross-device streaming Add local-network Companion Mode so a phone can control a tablet or TV on the same Wi-Fi/LAN, browse and stream titles in both directions, and hand off playback at the exact timestamp. Uses Android NSD (_mpvium._tcp.), NanoHTTPD with Range 206 streaming and SSE state updates, 4-digit PIN pairing, a haptic jog wheel and gesture touchpad, second-screen track/subtitle/MediaInfo/Anime4K controls, URL throwing, and Late-Night Private Audio. * fix(app): resolve Compose TV modifier and mpv command signatures in companion UI * fix(app): use existing R.string.close in CompanionScreen
…apters, sleep timer, and bookmarks
Deploying mpvium with
|
| Latest commit: |
11742d2
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3c5b1cfd.mpvium.pages.dev |
| Branch Preview URL: | https://companion-mode-v2.mpvium.pages.dev |
Reviewer's GuideSchema and migrationsAdd a persistent preference key for storing Companion moment bookmarks.
Data structuresExtend the Companion protocol models with chapter and sleep-timer playback state, bookmark records, and commands for chapter navigation and sleep timers.
APIExpose Watch Together playback and bookmark operations through CompanionManager so the UI can start synchronized playback, save moments, and revisit or delete bookmarks.
ImplementationReconnect Companion Mode networking and refresh discovery when Wi-Fi or Ethernet becomes available or is lost.
Publish chapter and sleep-timer state from the player bridge and handle remote chapter jumps and timer requests.
UIAdd peer-library search and kind filters, Watch Together and bookmark actions, chapter navigation, sleep-timer controls, and a saved-bookmarks list to Companion Mode.
Provide the preference locals required by the Companion Mode preference controls to prevent the settings-screen crash.
Add localized labels for Companion library filters and the new Watch Together, chapter, sleep-timer, and bookmark controls.
DocumentationRecord the Companion Mode additions and the preference-screen crash fix in the unreleased changelog.
TestsExtend Companion protocol tests to verify serialization of the new playback-state fields and bookmark records.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 16 issues
Sourcery assessment
Needs a human reviewer. 15 findings to address first, and bookmarks are saved in preferences, so incorrect entries can remain after a rollback, but the list is capped and users can delete them. The new remote playback controls can cause ordinary playback mistakes, which reverting the change would stop.
Blocking findings: app/src/main/java/app/aryan447/mpvium/ui/player/CompanionPlayerBridge.kt:6, app/src/main/java/app/aryan447/mpvium/domain/companion/CompanionManager.kt:378, app/src/main/java/app/aryan447/mpvium/domain/companion/CompanionManager.kt:686, app/src/main/java/app/aryan447/mpvium/domain/companion/CompanionManager.kt:700, app/src/main/java/app/aryan447/mpvium/domain/companion/CompanionManager.kt:685, and 10 more
| import app.aryan447.mpvium.domain.anime4k.Anime4KManager | ||
| import app.aryan447.mpvium.domain.companion.CompanionChapterInfo | ||
| import app.aryan447.mpvium.domain.companion.CompanionCommand | ||
| import app.aryan447.mpvium.domain.companion.CompanionChapterInfo |
There was a problem hiding this comment.
🔴 Critical · App fails to compile
When the Kotlin compiler processes this file, the duplicate CompanionChapterInfo imports conflict, so compilation fails and the app cannot build.
Remove the duplicate import.
| val url = when { | ||
| state.activeStreamUrl.startsWith("http://") || state.activeStreamUrl.startsWith("https://") -> state.activeStreamUrl | ||
| state.mediaId.isNotBlank() -> client.buildStreamUrl(peer, state.mediaId, token) | ||
| else -> return |
There was a problem hiding this comment.
🟠 High · Watch Together skips local files
When the peer is playing a local file, CompanionPlayerBridge.updateActiveMediaMeta has no callers, leaving mediaId blank while activeStreamUrl falls back to the player path. syncWatchWithPeer returns without starting playback, and bookmarks save no media ID, so a later jump seeks whichever item is currently playing.
Populate and publish the active media ID for local playback, and use it in Watch Together and bookmarks.
Also at app/src/main/java/app/aryan447/mpvium/domain/companion/CompanionManager.kt:377, app/src/main/java/app/aryan447/mpvium/domain/companion/CompanionManager.kt:393, app/src/main/java/app/aryan447/mpvium/domain/companion/CompanionManager.kt:410.
| if (preferences.enabled.get()) { | ||
| refreshNetworkStatus() | ||
| if (server == null) start() else discovery.startDiscovery(preferences.deviceId.get()) | ||
| } |
There was a problem hiding this comment.
🟡 Medium · Reconnected peer stays unreachable
When the peer's LAN address changes while this device reconnects, discovery.startDiscovery can find the peer's new address, but _connectedPeer and the SSE observer keep using the old CompanionDeviceInfo. Remote state and commands continue targeting the stale address, so the peer remains unreachable until the user reconnects manually.
Update the active peer connection and restart its observer with the newly discovered address.
| } | ||
| } | ||
| } | ||
| networkCallback = callback |
There was a problem hiding this comment.
🟡 Medium · Automatic reconnect stays disabled
When ConnectivityManager.registerNetworkCallback throws, networkCallback is assigned before registration, and runCatching swallows the exception. Later calls hit the non-null guard and skip registration, so automatic reconnect remains disabled for the manager's lifetime.
Clear networkCallback when registration fails so a later call can retry.
Also at app/src/main/java/app/aryan447/mpvium/domain/companion/CompanionManager.kt:701.
| delay(400) | ||
| if (preferences.enabled.get()) { | ||
| refreshNetworkStatus() | ||
| if (server == null) start() else discovery.startDiscovery(preferences.deviceId.get()) |
There was a problem hiding this comment.
🟡 Medium · Concurrent starts leak servers
When a manual start and an onAvailable callback (or two matching network callbacks) enter start() together, start() checks and assigns server without synchronization, so an explicit start and a network callback can both create and start servers before either assignment; one server is then overwritten and left running, with inconsistent discovery and port state.
Serialize server startup and recheck the running server inside that serialized section.
|
|
||
| val filtered = remember(items, query, kindFilter) { | ||
| items.filter { item -> | ||
| val matchesKind = kindFilter == "all" || item.kind == kindFilter |
There was a problem hiding this comment.
🟡 Medium · Series disappear from Shows filter
When a peer library contains items with kind series and the user selects Shows, the Shows chip sets kindFilter to episode, so matchesKind excludes peer library items whose kind is series; callers cannot find those titles while filtering for shows.
Treat both series and episode kinds as matches for the Shows filter.
| sleepTimerRemainingSec = -1 | ||
| sleepTimerJob = scope.launch(Dispatchers.Main) { | ||
| while (MpvPlayer.isReady) { | ||
| val pos = MpvPlayer.mpv.getPropertyDouble("time-pos") ?: 0.0 |
There was a problem hiding this comment.
🟡 Medium · Sleep timer waits through next video
When the player advances to another queued video before the next timer poll, the end-of-video job samples the current video's time-pos and duration without tracking which media it started on. It then waits for the next video to end before pausing, so playback continues past the intended end.
Track the media the job started on and stop the timer when playback advances to another item.
Also at app/src/main/java/app/aryan447/mpvium/ui/player/CompanionPlayerBridge.kt:317-318.
| "movie" to R.string.companion_filter_movies, | ||
| "episode" to R.string.companion_filter_shows, | ||
| ).forEach { (key, labelRes) -> | ||
| FilterChip( |
There was a problem hiding this comment.
🟡 Medium · TV controls lack focus rings
When the Companion screen is navigated with a TV remote, FilterChip and bookmark Surface/IconButton omit the project's tvFocusHighlight modifier, so TV users navigating to these controls get no clear D-Pad focus ring and cannot readily identify the current target.
Apply tvFocusHighlight to each newly added interactive control.
Also at app/src/main/java/app/aryan447/mpvium/ui/companion/CompanionScreen.kt:1545, app/src/main/java/app/aryan447/mpvium/ui/companion/CompanionScreen.kt:1568, app/src/main/java/app/aryan447/mpvium/ui/companion/CompanionScreen.kt:1587.
From AGENTS.md L125-128:
11. Keep the app fully navigable by remote control for Android TV and Google TV.
Ensure interactive elements maintain clear D-Pad focus rings, handle
DPAD/remote key events cleanly, and adapt layouts (e.g., width constraints
on settings and sheets) for wide 16:9 television viewing.| onClick = { | ||
| haptic.performHapticFeedback(HapticFeedbackType.SegmentTick) | ||
| onCommand(CompanionCommand(action = CompanionCommand.ACTION_SET_SLEEP_TIMER, intValue = mins)) | ||
| }, |
There was a problem hiding this comment.
🟡 Medium · Older peers silently ignore new controls
When the phone has this update but the connected host is running an older Companion Mode version, an older peer decodes the new action as a string but has no handler for it; its command path still reports success. The sleep timer appears selectable on the phone, but the host does nothing and the UI receives no error.
Advertise protocol capabilities and gate the new controls on host support, or make unsupported actions return an explicit error.
| @@ -1,4 +1,5 @@ | |||
| ### Added | |||
| - Added Watch Together sync playback, chapter navigation, remote sleep timer, moment bookmarks, searchable peer title filtering, and automatic Wi-Fi reconnect to Companion Mode. | |||
There was a problem hiding this comment.
⚪ Low · Changelog remains stale
When the PR changes user-visible behavior, the user-facing additions and fix are recorded only in UNRELEASED.md, while CHANGELOG.md has no corresponding notes, leaving the repository's required paired release-note update incomplete.
Add corresponding user-facing notes to CHANGELOG.md in this same change.
Also at UNRELEASED.md:3, UNRELEASED.md:15.
From AGENTS.md L233:
- Update both files in the same change that alters user-visible behavior.
Summary
Fixes the
LocalPreferenceTheme not presentcrash inCompanionPreferencesScreenand expands Companion Mode with Watch Together sync playback, chapter navigation, remote sleep timer, moment bookmarks, searchable/filterable peer title browsing, and automatic Wi-Fi reconnect.Fixes & Improvements
CompanionPreferencesScreeninProvidePreferenceLocalssoHapticSwitchPreferencehasLocalPreferenceTheme.ConnectivityManager.NetworkCallbackinCompanionManagerto automatically start/refresh server & NSD discovery when Wi-Fi or Ethernet connects.New Companion Features
15m,30m,45m,60m, orEnd of videosleep timer on the TV/tablet from the phone with a live countdown.Before / After
LocalPreferenceTheme not present; peer title browser showed at most 25 unfiltered items; no sleep timer, chapter list, bookmarks, or Watch Together mode.How measured
Unmeasured (crash fix verified by inspection + CI build/unit tests).
Verification
git diff --check: passed cleanly.CI BuildandUnit Teststriggered oncompanion-mode-v2.Changelog
UNRELEASED.mdunderAddedandFixed.Risks
Summary by Sourcery
Expand Companion Mode with cross-device playback controls and browsing while making its settings screen open reliably.
New Features:
Bug Fixes:
Enhancements:
Tests:
Chores: