So far the only way I found is to call ListNames method on org.freedesktop.DBus
periodically, and check if any org.mpris.MediaPlayer2.*
is added or removed.
But isn't there a better way? For example, is there a D-Bus signal notifying about changes in the list of bus names, to avoid calling ListNames
periodically?
The signal is NameOwnerChanged on the org.freedesktop.DBus
bus. It has 3 arguments: name, old owner, and new owner.
If there is no old owner (empty string), only a new one, then the name was added. And vice-versa, if there is no new owner, then the name was removed.
To filter players-only bus names the name can be checked to start with org.mpris.MediaPlayer2
.