Skip to content

Add MPRIS support via go-music-players/mpris library#44

Open
stashluk wants to merge 2 commits intoshinokada:mainfrom
stashluk:integrate-go-music-players-mpris
Open

Add MPRIS support via go-music-players/mpris library#44
stashluk wants to merge 2 commits intoshinokada:mainfrom
stashluk:integrate-go-music-players-mpris

Conversation

@stashluk
Copy link
Copy Markdown

@stashluk stashluk commented Feb 1, 2026

This PR adds optional MPRIS2 support for desktop integration with media players and system controls.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added MPRIS2 support via --mpris command-line flag, enabling control through external media applications, system interfaces, and third-party media control tools
    • Added --version flag for quick version information display
    • Enhanced command-line help documentation and argument parsing

✏️ Tip: You can customize this high-level summary in your review settings.

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 1, 2026

Deploy Preview for terminal-radio ready!

Name Link
🔨 Latest commit e270383
🔍 Latest deploy log https://app.netlify.com/projects/terminal-radio/deploys/697fcf3a26abaf0008fbb104
😎 Deploy Preview https://deploy-preview-44--terminal-radio.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 1, 2026

Warning

Rate limit exceeded

@stashluk has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 23 minutes and 21 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

This pull request adds MPRIS2 (Media Player Remote Interfacing Specification) support to the radio player application. A new MPRISAdapter translates the existing MPVPlayer to the MPRIS interface, enabling external media control. CLI support includes a -mpris flag to enable the feature, and the QuickFavPlayer field is exported for MPRIS access. The MPRIS server initializes conditionally during startup before the UI launches.

Changes

Cohort / File(s) Summary
MPRIS Integration
cmd/tera/main.go, go.mod, internal/player/mpris_adapter.go
Added MPRIS2 support with new -mpris CLI flag, dependency imports (github.com/go-music-players/mpris and github.com/godbus/dbus), and MPRISAdapter implementation. Adapter implements playback control (Play, Pause, Stop), metadata retrieval (station info), and capability reporting tailored for radio playback semantics.
Player Export
internal/ui/app.go
Renamed unexported quickFavPlayer field to exported QuickFavPlayer to allow MPRIS adapter access, with all internal references updated correspondingly.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI / main()
    participant MPRISAdapter as MPRISAdapter
    participant MPRISServer as MPRIS Server
    participant Player as MPVPlayer
    participant UI as Bubble Tea UI

    CLI->>CLI: Parse -mpris flag
    CLI->>MPRISAdapter: NewMPRISAdapter(app.QuickFavPlayer)
    activate MPRISAdapter
    MPRISAdapter->>Player: Store reference
    deactivate MPRISAdapter
    
    alt MPRIS enabled
        CLI->>MPRISServer: NewServer(adapter)
        activate MPRISServer
        MPRISServer->>MPRISServer: Register MPRIS interface
        deactivate MPRISServer
        Note over CLI: On failure: log warning, continue
        Note over CLI: On success: defer server.Close()
    end
    
    CLI->>UI: NewApp() + tea.NewProgram()
    activate UI
    UI->>UI: Start Bubble Tea event loop
    deactivate UI
    
    Note over MPRISServer,Player: External MPRIS clients can now control playback
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 With flags and adapters, our player takes flight,
MPRIS whispers commands through the night,
From station to speaker, the signals align,
A radio's refrain, now remote and divine! 🎙️✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding MPRIS support via the go-music-players/mpris library, which is the primary objective of this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/tera/main.go (1)

54-80: ⚠️ Potential issue | 🟠 Major

--mpris is never set when it's the first argument.

In the case "--mpris": branch (line 73), you parse os.Args[2:], which drops the flag itself, so enableMpris remains false and tera --mpris does nothing.

Proposed fix
 	case "--mpris":
 		// Parse remaining flags
+		*enableMpris = true
 		flag.CommandLine.Parse(os.Args[2:])
🤖 Fix all issues with AI agents
In `@internal/player/mpris_adapter.go`:
- Around line 19-33: Play() currently no-ops; implement it to resume the current
station by calling the player's GetCurrentStation() and, if non-nil/valid, call
Play(station) and return its error; if no current station, return nil. Also
update CanPause() to return a.player.IsPlaying() (true only when actively
playing) instead of always true so the MPRIS state reflects actual pause
capability. Ensure you use the existing methods a.player.GetCurrentStation(),
a.player.Play(station), and a.player.IsPlaying() and preserve error propagation
from Play(station).

Comment thread internal/player/mpris_adapter.go
@stashluk stashluk force-pushed the integrate-go-music-players-mpris branch from 957428d to 6277040 Compare February 1, 2026 21:40
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
internal/ui/app.go (1)

392-454: ⚠️ Potential issue | 🔴 Critical

Fix remaining quickFavPlayer references (compile error).

After the rename, the volume-control block still uses a.quickFavPlayer (Line 392/397/413/429). That field no longer exists, so the file won’t compile. Replace those with a.QuickFavPlayer.

🛠️ Proposed fix
-	if a.playingFromMain && a.quickFavPlayer != nil {
+	if a.playingFromMain && a.QuickFavPlayer != nil {
 		switch msg.String() {
 		case "/":
 			// Decrease volume
-			newVol := a.quickFavPlayer.DecreaseVolume(5)
+			newVol := a.QuickFavPlayer.DecreaseVolume(5)
@@
 		case "*":
 			// Increase volume
-			newVol := a.quickFavPlayer.IncreaseVolume(5)
+			newVol := a.QuickFavPlayer.IncreaseVolume(5)
@@
 		case "m":
 			// Toggle mute
-			muted, vol := a.quickFavPlayer.ToggleMute()
+			muted, vol := a.QuickFavPlayer.ToggleMute()
cmd/tera/main.go (1)

53-80: ⚠️ Potential issue | 🟠 Major

--mpris flag is never set when passed as first argument.

When os.Args[1] == "--mpris", the code matches this in the switch statement and calls flag.CommandLine.Parse(os.Args[2:]), which skips the --mpris argument entirely. The flag parser never sees it, leaving enableMpris false and preventing MPRIS from being enabled.

🛠️ Proposed fix
 	case "--mpris":
 		// Parse remaining flags
+		*enableMpris = true
 		flag.CommandLine.Parse(os.Args[2:])

Add optional MPRIS2 (Media Player Remote Interfacing Specification)
support to enable desktop media controls, system keyboard shortcuts,
and Now Playing widgets on GNOME/KDE environments.

Changes:
- Add MPRISAdapter bridging MPVPlayer to MPRIS interface
- Implement Play() to resume current station if available
- Add --mpris CLI flag to enable MPRIS server
- Export App.QuickFavPlayer for MPRIS adapter access
- Add go-music-players/mpris v0.1.0 dependency
- CanPause() returns IsPlaying() to reflect actual pause capability

Since tera is a radio player, Next/Previous and Seek operations
are disabled as they don't apply to live radio streams.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@stashluk stashluk force-pushed the integrate-go-music-players-mpris branch from b1e6376 to dcf10cf Compare February 1, 2026 22:08
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.

1 participant