Skip to content

Add native MPRIS support on Linux#950

Open
BlueManCZ wants to merge 1 commit intomartpie:masterfrom
BlueManCZ:native-mpris
Open

Add native MPRIS support on Linux#950
BlueManCZ wants to merge 1 commit intomartpie:masterfrom
BlueManCZ:native-mpris

Conversation

@BlueManCZ
Copy link
Copy Markdown
Contributor

Summary

  • Replace WebKitGTK's built-in navigator.mediaSession MPRIS integration with a native Rust implementation using the mpris-server crate
  • The player now appears as museeks in playerctl -l instead of org.webkit.app-<hash>.Sandboxed.instance-<N>
  • On Linux, audio playback uses the Web Audio API instead of <audio> element to prevent WebKitGTK's MPRIS entry from reporting active playback status
  • macOS/Windows continue to use navigator.mediaSession

MPRIS features supported

  • Play, pause, play/pause, stop, next, previous
  • Shuffle (get/set)
  • Loop status (None/Track/Playlist)
  • Volume (get/set, with perceptual scaling matching the UI slider)
  • Seek (absolute and relative)
  • Position tracking
  • Track metadata (title, artist, album, track number, duration, cover art)

Changes

Backend (Rust)

  • New: src-tauri/src/plugins/mpris.rs — Native MPRIS server plugin using mpris-server crate with bidirectional IPC
  • Modified: src-tauri/src/plugins/stream_server.rs — Added CORS header for Web Audio API fetch() compatibility
  • Modified: src-tauri/src/libs/events.rs — Added PlaybackSeekTo, PlaybackSeekBy, PlaybackSetVolume,
    PlaybackSetShuffle, PlaybackSetRepeat IPC events

Frontend (TypeScript)

  • New: src/lib/bridge-mpris.ts — IPC bridge for MPRIS commands (no-op on non-Linux)
  • New: src/lib/web-audio-element.ts — Drop-in HTMLAudioElement replacement using AudioContext so WebKitGTK's MPRIS
    entry stays inactive
  • Modified: src/lib/player.ts — Uses WebAudioElement on Linux, syncs state to native MPRIS, adds
    setShuffle/setRepeat methods
  • Modified: src/lib/utils-player.ts — Extracted shared volume smoothing helpers
  • Modified: src/components/VolumeControl.tsx — Uses shared volume smoothing helpers
  • Modified: src/components/IPCPlayerEvents.tsx — Handles new MPRIS-originated events (seek, volume, shuffle, repeat)

Test plan

  • playerctl -l shows museeks (the org.webkit.app-... entry may exist but stays in Stopped status)
  • playerctl metadata shows title, artist, album, artUrl, length
  • playerctl play, pause, play-pause, next, previous, stop
  • playerctl shuffle On / Off
  • playerctl loop None / Track / Playlist
  • playerctl volume 0.5 sets the UI slider to 50%
  • playerctl position 30 (absolute) and playerctl position 10+ (relative)
  • Desktop environment media controls (GNOME/KDE) work
  • App builds and runs on macOS/Windows (MPRIS code is cfg-gated, mediaSession still works)

Copy link
Copy Markdown
Owner

@martpie martpie left a comment

Choose a reason for hiding this comment

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

oof. Thanks for this, but not sure how I feel about it, this is a lot of code specific to Linux.

I'll check is there are easier way to solve the issues you mentioned. If not, then I'll check this PR again.

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