-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor(jukebox): Switch to MPV-based management with singleton #4208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Daniel Evans <me@daredoes.work>
Signed-off-by: Daniel Evans <me@daredoes.work>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @daredoes, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly refactors the jukebox playback mode by moving from a per-track MPV process model to a single, persistent MPV instance controlled via IPC. This change aims to address existing issues and provide a more robust foundation for jukebox functionality. A new Lua script is introduced to bridge the gap between MPV's playlist management and Navidrome's media file IDs.
Highlights
- Single MPV Instance: The jukebox mode is refactored to use a single, long-running MPV process instead of launching a new process for each track. This is expected to improve stability and performance.
- IPC Communication: Control of the MPV process is now handled via its IPC socket, allowing Navidrome to send commands (play, pause, skip, etc.) and query status.
- Lua Script for Playlist Management: A custom Lua script is added to MPV. This script maintains a cache mapping file paths to Navidrome media file IDs and exposes the ordered list of IDs in the current MPV playlist via an MPV property, which Navidrome can then query.
- Refactored Playback Logic: The
playbackDevice
andPlaybackServer
components are updated to delegate playback control actions (Add, Clear, Remove, Start, Stop, Skip, SetGain, Shuffle, Get, Status) to the single MPV connection managed by thePlaybackServer
. - Updated MPV Command Template: The default MPV command template is modified to remove the per-file argument (
%f
) and include the new Lua script using the--script
option.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request significantly refactors the jukebox mode to use a single, persistent MPV process managed via an IPC socket and a Lua script, instead of launching an MPV process per track. This is a substantial improvement for stability and resource management.
The changes involve:
- Introducing an
MpvConnection
incore/playback/mpv/mpv.go
to manage the single MPV instance and its IPC communication. - Adding a Lua script (
jukebox.lua
) that runs within MPV to provide playlist information (track IDs) back to Navidrome. - Modifying
core/playback/playbackserver.go
to be the central point for MPV control, holding theMpvConnection
and exposing methods for various playback actions. - Updating
core/playback/device.go
to delegate most Jukebox commands to thePlaybackServer
. - Adjusting Subsonic API helpers and Jukebox control logic to work with track IDs instead of full
MediaFile
objects directly from the playlist.
Overall, the refactoring appears well-executed and addresses the core issue of multiple MPV processes. The use of a Lua script for playlist data retrieval is a clever solution.
I've identified a few areas for improvement related to correctness and robustness.
@tcurdt Could I get your input on this PR? |
I am not sure I am the one to give input but since you asked for it... I like how you separated out the player state. How would adding Overall it's looks like great improvements. Very cool. |
@tcurdt I appreciate the review! You're the most active contributor besides myself that I can think of who is specifically trying to use this for snapcast playback. The lua script is required since MPV now manages the playlist while we still need to return data about the playlist in the
An action that I'd like to support in the API, but isn't outlined anywhere, is the ability to loop a playlist, or loop the playing song. It's supported by MPV very easily, but it is not documented in the subsonic API. This would make it an extension on the current standard. To be fair, the current standard doesn't seem to be widely adopted or actively improved. |
@deluan I'd love to get this looked at and merged in at some point if you have the time |
Bump :( waiting to start on creating UI/UX for this feature until its merged in for testing against |
Bumping again I guess :( librespot broke recently and this would have been awesome to fall back to. |
@deluan Hope the ping isn't a bother. Trying not to let this PR get lost to time. |
WORKING JUKEBOX MODE!
still needs a high quality controller though
The jukebox mode as it is implemented has many issues, part of which came from using an MPV process per track, instead of an MPV process for all tracks. MPV is super powerful, but the documentation is not ripe with examples of what to do. Through trial and error (and some Google Gemini to help with the unknown MPV stuff) I have come about with the minimum viable solution for Navidrome to have a working jukebox mode (and learned a lot about MPV).
Creating a file with
mkfifo /tmp/navidrome
and running navidrome (this branch) and snapcast on the same system seems to work. Running snapcast via docker and navidrome locally does not work on my mac. Might have something to do with file binding, or how the pipe works, idk.The file between the two must be made with mkfifo as far as I can tell, otherwise mpv writes the content too fast
Template command
The magic of how this feature works
MPV has a lot of great features built-in, but not everything. To supplement that, it supports running plugin scripts. Through usage of a custom plugin script we can attach IDs to each track we load in to play, allowing us to later retrieve the current playlist from MPV and fetch the data from our database for the
get
action. This provides apps with all the information needed for cover art.Optimizations
MPVNoAudioDisplay
Features Supported
The following features would be nice to implement as they are supported by MPV. They would be an extension of the subsonic api
Closes #3256
Changes
Screenshots or Videos
Related Issues and Pull Requests(if any)
#3852
#3637
#3022
#2771