Skip to content

Add now-playing media widget (registered apps, no special permission)#158

Merged
luantak merged 2 commits into
luantak:masterfrom
mesmerverse:feature/media-widget
Jul 1, 2026
Merged

Add now-playing media widget (registered apps, no special permission)#158
luantak merged 2 commits into
luantak:masterfrom
mesmerverse:feature/media-widget

Conversation

@mesmerverse

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in media widget to the home screen, shown below the date/battery row whenever audio is playing. It has two lines:

  • Top: scrolling now-playing text (Title — Artist). Tapping it opens the playing app (its now-playing screen when the app offers one).
  • Bottom: ⏪ rewind 15s · ⏯ play/pause · ⏩ forward 30s. The seek buttons dim and disable for apps that don't support seeking (e.g. live streams).

Permission-free by design

Rather than a NotificationListenerService (which needs the sensitive "Notification access" grant), the widget connects directly to user-registered apps via MediaBrowserCompat — no special permission is requested at all. Under Settings → Configure widgets, enabling "Show media controls" reveals a Media apps picker listing installed apps that expose a MediaBrowserService; the widget connects to the ones the user registers and shows whichever is playing.

Note: an app only connects if it permits outside connections (its onGetRoot accepts us). Many players (podcast apps, VLC, etc.) do; some mainstream apps whitelist only system callers and won't connect — hence the per-app, opt-in registration model.

Changes

  • media/MediaRepository — discovers media-browser apps, manages per-app browser/controller connections, exposes now-playing StateFlow + transport controls. Opens the session's PendingIntent with the background-activity-start mode so it works on Android 14+.
  • ui/components/MediaWidget — the two-line Compose widget, themed to match the other widgets (uses the accent color).
  • Home + Settings ViewModels wired up; new show_home_media preference (default off) and a registered_media_apps set.
  • <queries> entry for MediaBrowserService so apps are discoverable on Android 11+; adds the androidx.media dependency.
  • Unit tests for the seek-offset math.

Testing

Built a debug APK and verified on a physical device: registered AntennaPod, confirmed the now-playing line, scrolling text, play/pause, ±seek, and tap-to-open (opening the app's now-playing screen). Existing HomeViewModelTest updated and passing.

🤖 Generated with Claude Code

Adds an opt-in, two-line media widget below the home date/battery row that
shows the current track (scrolling title — artist) and rewind 15s /
play-pause / forward 30s controls. Tapping the title opens the playing app.

Reads and controls playback by connecting to user-registered apps via
MediaBrowserCompat, so it needs no notification-access or other special
permission — apps that allow outside connections appear in a picker under
Settings → Configure widgets and are connected on demand.

- media/MediaRepository: discovers MediaBrowserService apps, manages
  per-app browser/controller connections, exposes now-playing state and
  transport controls (play/pause, seek ±, open app).
- ui/components/MediaWidget: the two-line Compose widget.
- Wires media state/controls through Home and Settings ViewModels; adds a
  show-media preference and a registered-apps set.
- Grants the background-activity-start mode when opening via the session's
  PendingIntent so it works on Android 14+.
- Auto-hides a session that stays paused past a 60s grace period, so apps
  that leave a paused session alive after closing don't keep the widget up.
- Unit tests for the seek-offset math.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mesmerverse
mesmerverse force-pushed the feature/media-widget branch from 49c3f41 to e38df71 Compare June 28, 2026 19:50
@luantak

luantak commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Unfortunately this doesn't work with spotify at all so I'll be using the notification access way, open to a new PR if you find a way that doesnt require notification access but still supports spotify

Drive now-playing controls from MediaSessionManager through a notification
listener, with skip/like/save actions, buffering support, and settings that
gate the feature on notification access in a single toggle.
@luantak
luantak merged commit ff87633 into luantak:master Jul 1, 2026
2 checks passed
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.

2 participants