Skip to content
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

DBus PropertiesChanged event not fired #457

Closed
2 of 6 tasks
mainrs opened this issue Dec 17, 2019 · 11 comments · Fixed by #1025
Closed
2 of 6 tasks

DBus PropertiesChanged event not fired #457

mainrs opened this issue Dec 17, 2019 · 11 comments · Fixed by #1025
Labels
bug A functionality or parts of a program that do not work as intended good first issue An easy to implement issue, good for first time contributors or people new to open source pinned Apply to make stale bot ignore issue/PR.
Milestone

Comments

@mainrs
Copy link
Member

mainrs commented Dec 17, 2019

Description

Metadata changes do not raise the org.freedesktop.DBus.Properties.PropertiesChanged event

Compilation flags

  • dbus_mpris
  • dbus_keyring
  • alsa_backend
  • portaudio_backend
  • pulseaudio_backend
  • rodio_backend

Versions (please complete the following information):

  • OS:
  • Spotifyd:
  • cargo:

See #455

@mainrs mainrs added bug A functionality or parts of a program that do not work as intended good first issue An easy to implement issue, good for first time contributors or people new to open source labels Dec 17, 2019
@mainrs mainrs added this to the v0.2.21 milestone Dec 17, 2019
@justin-gerhardt
Copy link
Contributor

justin-gerhardt commented Dec 17, 2019

I've tried implementing this a bit but I'm over my head with rust.
The dbus library has native support for the propertiesChanged event.
The properties have to have tagged .emits_changed(dbus::tree::EmitsChangedSignal::True) (invalidate doesn't work with playerctl)

Normally the signal is sent by the library automatically on property modification from dbus. In this case since the change is internal it has to be manually sent.
A relevant github issue diwic/dbus-rs#66
The only result on github I could find that uses the API
You should also note that the signal will not appear on the introspection API. It is however still sent.

Ideally the signal would be raised for the metadata, playback status and position properties.

@mainrs
Copy link
Member Author

mainrs commented Dec 17, 2019

Would you mind trying out if the version over at https://github.com/Spotifyd/spotifyd/tree/fix_propertieschanged_event ? This might work but I can't really try it because I don't have access to a linux env right now @justin-gerhardt

It should specifically only fix the metadata problem.

@justin-gerhardt
Copy link
Contributor

justin-gerhardt commented Dec 17, 2019

Setting emits_changed alone only raises the signal if the property change was caused by a dbus message setting the metadata property (which can't happen, it's read only). dbus-rs has no way of knowing that fetching the underlying metadata would result in a new result.

You will have to somehow feed metadata change events into the dbus server and then run something along the lines of

let mut chg = Vec::new();
property_metadata.clone().add_propertieschanged(&mut chg, media_player2_player_interface.get_name(), ||{
     Box::new(// new metadata)
});
let msg = chg.first().unwrap().to_emit_message(object_path.clone().get_name());
connection.clone().send(msg).unwrap();

every time the metadata changes
Note: I've wrapped the property in an Arc

@JasonLG1979
Copy link

Ideally the signal would be raised for the metadata, playback status and position properties.

DO NOT emit a property changed signal for position. That would result in a crazy amount of signals.

The spec clearly says not to.

"The org.freedesktop.DBus.Properties.PropertiesChanged signal is not emitted when this property changes."

https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:Position

@JasonLG1979
Copy link

My advice on properties are this:

  1. Read the spec of the interfaces you implement. It will tell you if a property changed signal is expected. (most of the time it is with a couple exceptions)

  2. Include ALL properties for the interfaces you implement even if you do not plan on changing them.

  3. TrackId in the metadata is important, especially if you plan on implementing the TrackList interface.

  4. Do not put up an empty interface. make sure that all properties will return at least a default value before you expose the interface.

  5. When going from track to track you do not need to update the playback status unless it actually changes. (I see a lot of players that send redundant playback status prop change signals.)

  6. You don't have to worry about batching signals, Send the signals when something changes don't wait. The flip side to that is also don't machine gun a bunch of redundant signals. (I see that a lot too.)

@stale
Copy link

stale bot commented Jan 13, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix Issues that will not be fixed under any circumstances label Jan 13, 2021
@real-or-random
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I don't think that this issue has been solved.

@stale stale bot removed the wontfix Issues that will not be fixed under any circumstances label Jan 13, 2021
@slondr slondr added the pinned Apply to make stale bot ignore issue/PR. label Jan 16, 2021
@MDeiml
Copy link
Contributor

MDeiml commented Nov 17, 2021

I have a fix for this coming, but it depends on #977 which is about to get merged.

@capnfabs
Copy link
Contributor

#977 apparently needs a second review before I can merge it :(

@capnfabs
Copy link
Contributor

Also @MDeiml, don't know how far along your fix is, but this branch (master...capnfabs:main) has a working implementation of MPRIS with change notifications in case you want to borrow things from it!

It, however, also relies on underlying changes to librespot so that it doesn't have to make requests to the Spotify API; I got approval for that from the librespot team here (librespot-org/librespot#834) and then life got in the way and I never did anything about it 😅

Just in case any of that is helpful :)

@MDeiml
Copy link
Contributor

MDeiml commented Nov 19, 2021

@capnfabs Oh, my fix is only a few lines, I mostly just leverage the player event channel. It still uses the web API so it's probably a bit slower and less reliable than what you tried to achieve.

Unrelated to that I also looked at if we could reduce usage of the web API by instead getting info from librespot since that seems to be the cause of some delays like in #891, but I ran into the same problems as you did. librespot does not expose all the data that the web API does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A functionality or parts of a program that do not work as intended good first issue An easy to implement issue, good for first time contributors or people new to open source pinned Apply to make stale bot ignore issue/PR.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants