-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
mpris2 support #661
Comments
Unlikely. It requires dbus. We certainly don't want to depend on dbus or any dbus client libraries. Also, these dbus client libraries are either horrible to use, or depend on entire toolkits (Qt/GTK). |
If you want to get the type of data available from mpris2 you can use This is written to stderr so if you redirect stderr to somewhere where the program you wanted to get the mpris2 data can read and parse it you can get the data that way. This can be used to do things like displaying progress bars in other programs, in this case conky. I would not use this method for anything but personal scripts however since redirecting stderr prevents status output (like real error messages) from being displayed to the user in the terminal. It used to be possible to use bash redirection to show stderr in the terminal and send it elsewhere but that stopped working in the master branch most likely due to this commit. It is also kind of complex since I had to use three scripts to make my example work.
It may be possible to use the Lua scripting added with the OSD to write the pertinent data out to a text file as well but I have not investigated that possibility yet. I also agree with you wm4, dbus libraries are horrible to use. |
Github's rst render is broken or doesn't support this. Anyway, it's a section input.rst.
Yes that should definitely be possible. In context of this issue, a Lua script could even load dbus libraries and implement mpris in Lua (if there is a Lua dbus library; I don't know). |
Depending on how lua scripts are run in mpv it may not be useable with mpv however. If it works like that I suspect the dbus library would not work because the dbus connection would die and be reopened every time the script runs (every screen update?). You could possibly work around this using one the multithreading Lua libraries. |
In git master, Lua scripts run in their own thread. By default, Lua a script is loaded only once. After initialization it enters an event loop, which waits for mpv event and dispatches them to callbacks registered by the script. So, usually, the script sets up event handlers, and then returns to C, and then C calls the event loop (which is written in Lua, see player/lua/defaults.lua, mp_event_loop). But in theory, a script could do something else, like enter a dbus dispatch loop (?) and poll for mpv events instead. (Note that this is only so in git master. mpv 0.3.x is entirely different.)
Looks like this requires a complicated "mainloop" abstraction, and there are pre-made glib and libev mainloop implementations. Sounds like a pain to integrate. I don't think they would add much value in this case. |
In that case what I think you would do is have your Lua script on load create a Lua table with dummy entires to be used to make replies to dbus queries. Then you would create and attach the dbus interface to the session bus and start listening for queries. Learning to use the dbus library and writing the functions to implement the mpris2 specification would be the hard and annoying part.
It was the only one I found that was still being maintained, the other one was from 2009. |
Well, the main problem is that both the dbus code and the mpv code want to wait for events. So they have to work somehow together, on some level. How that can be accomplished depends entirely on the dbus code. The mpv code could be changed to help with that. For example, it might be possible that the dbus API allows listening to an additional user provided file descriptor. Then mpv could provide a "wakeup pipe" that gets written if a mpv event happens, which would wakeup the dbus event loop, and would allow the Lua script to check for mpv events. Anyway, trying to integrate dbus and Lua (or dbus and anything) is probably messy. |
I doubt that is possible since we are not actually setting up all of dbus (the session bus is created when you login). If it is possible to request data from mpv at anytime from a Lua script and not on a mpv event you could have the Lua script just get that data from mpv inside the functions called by the dbus hooks. I think it is more trouble than it's worth to work on though since dbus is just annoying in general. |
That doesn't really have to do with anything. I'm talking about dbus API usage (whatever that API is, there are multiple). Not really sure what you're talking about, maybe you're misunderstanding something, or we're somehow talking past each other.
The main problem is that the dbus API has to do this "catching" somewhere, like a loop that calls select() or poll() on a dbus socket, and reads messages from there. So where does it do that? It could start a thread, but then you need some major synchronization. Or it could require a mainloop abstraction, like glib... then code using that dbus API has to use dbus too. And so on...
Yes, that's possible. But again, the question is how you integrate dbus operation (i.e. event loop) with the mpv/Lua event loop. How easy or hard this is depends on many things. |
I think it is a little of both. |
Would it be possible to expose a mp.has_event function? Then you can easily create your own GSource for mpv events and use lua-lgi with a glib mainloop. You can already work with it, but it might not be really easy. I'll try to throw something together. |
FWIW, I did look into this a while ago, but I ended up writing https://github.com/ghedo/grooved (warning, ugly code ahead) because I needed additional features. The libdbus is actually rather "lightweight" (at least in terms of dependencies, since it only depends on libc), and it gets pulled in anyway due to libpulse. The mpris support could be made so that if there's no dbus daemon running, it simply is disabled. The basic libdbus API is kinda convoluted and it requires a bit of glue code to make it work with an external IO loop, but it's doable and it shouldn't interfere much with the rest of mpv. |
Here is a basic example for mixing a glib context with the lua mpv loop. Sadly this forces us to use active polling. Would it be possible to trigger a file descriptor when events arrive?
|
Sure. Does glib provide something? Or do we have to create a "wakeup pipe" ourselves? |
mpv should provide a pipe that is triggered during |
Well, I can add such a pipe. Of course mpv itself can't provide code for adding a GSource (unless we add a dependency on glib, which we definitely don't want). I'll also look whether it's possible to reuse the Lua event loop provided by mpv in such a scenario. |
That might be something for external C plugins, except that we don't provide such a thing yet. As for libdbus, I want to avoid it as direct mpv dependency as far as possible. |
Pretty much experimental for issue #661.
OK added some stuff. See the commit github mentioned, and following commits. |
Pretty much experimental for issue mpv-player#661.
Is is possible to use mpris interface (with some lua scripts?) now? |
Not that I know of. |
This would be really great to have. MPRIS2 is being used for usecases that are just magical. For example, when my phone rings, KDE Connect uses MPRIS2 to stop running video or music playback on my media center PC, and resumes playback once the call is finished. This works like a charm with e.g. VLC, but sadly not with mpv. |
Hi, i wrote https://github.com/dodo/lua-mpris to overcome this problem (using kdeconnect as well) and to add mpris controls to the awesome window manager. Sadly most of the documentation is missing and the ldbus package needs installation by hand (plus my PR is required). But if you know lua and dbus and stuff you can start using it, yay. |
So does this script solve the issue? (Also I think the installation instructions for this script might be busted.) |
Thanks for the hint. Added some install instructions to the readme. Yes, that script solves this issue. |
@dodo: added your script to the wiki. I think I hereby consider this issue resolved. |
@dodo's script appears to be unmaintained, as it's currently buggy but hasn't received any work to resolve it in months. Seeing as mpv is a media player and mpris2 is an API designed for media players on Unix desktops, wouldn't it make more sense to have mpris2 support built-in?
Any external script providing mpris2 support will most likely use libdbus at some point; making libdbus an optional dependency doesn't seem too much of a horrible solution considering you already have quite a few optional dependencies on things such as samba or youtube-dl. |
I just want no dbus code in mpv. |
@wm4 I can understand that. DBus certainly isn't pretty as an API and the library isn't either. However, sadly it is currently pretty much the standard for desktop-oriented inter-process-communication on Linux. Seeing as libmpv is now a thing, do you think this functionality would be more appropriate for something wrapping mpv into a Linux desktop oriented player? |
There's the https://github.com/gnome-mpv/gnome-mpv wrapper which has an MPRIS service. |
The easiest way would be to use a third party bridge wrapping MPRIS to the mpv JSON RPC, I guess? I use such an MPRIS <-> mpd wrapper on my phone, so the lockscreen's player controls can interact with the mpd audio player. For the record I also want no dbus code in mpv. Dbus doesn't need more support than it's already getting, and the mpv JSON RPC works fine for its purpose. |
That is also another possible solution. Not sure what you do with multiple mpv instances though… |
Every instance would obviously need its own json socket. |
I want mpv but I also want mpris support 😞 |
@mathstuf You run the music in one and play a stream in the other for example. Or keep multiple streams open and muted, while listening to one. The first reason is why I've come here looking. |
Is mpris support related to having mpv use global media hotkey shortcuts? I would like to be able to control mpv via, for instance, Fn+F11 to pause/play. |
@orschiro For that you'd probably want to use the JSON IPC mechanism |
Thank you @mibli! How would I use your approach, for instance on Ubuntu 16.10? How do I map your commands to my media playback buttons without disabling these hotkeys for my other applications? -R |
I have finally got a minimal working MPRIS2 plugin using the lgi library for lua |
Nice. :-) How does one use it? -R |
@orschiro, I ran it with |
OK I added C plugin support: 44e06b7 If anyone really wants mpris2 support and hates Lua, he could try writing a mpris2 plugin with this. |
If anyone is still interested, I have created a C plugin for this fully implementing the basic MPRIS2 spec https://github.com/hoyon/mpv-mpris |
Very nice. Will inquire with my distribution if they can |
@hoyon probably best to create a cplugins section on this page, and add a link to it: https://github.com/mpv-player/mpv/wiki/User-Scripts |
@wm4 Added it to the wiki |
I was wondering if it's a possibility in the future.
The text was updated successfully, but these errors were encountered: