-
Hello, I am trying to use dasbus library to control my media, but I am stuck and I would love your help. from dasbus.connection import SessionMessageBus
bus = SessionMessageBus()
for service in bus.proxy.ListNames():
if 'MediaPlayer2' in service:
proxy = bus.get_proxy(service, "/org/mpris/MediaPlayer2")
playback_status = proxy.Get("org.mpris.MediaPlayer2.Player", "PlaybackStatus")
metadata = proxy.Get("org.mpris.MediaPlayer2.Player", "Metadata")
position = proxy.Get("org.mpris.MediaPlayer2.Player", "Position")
proxy.PlayPause() I am able to get the metadata/position/playbackstatus, but I can't control it because the PlayPause attribute doesn't exist. This is the traceback of the code above: Traceback (most recent call last):
File "/home/bkbilly/Documents/dbus_mediaplayer.py", line 10, in <module>
proxyplayer.PlayPause
File "/home/bkbilly/venv/lib/python3.12/site-packages/dasbus/client/proxy.py", line 161, in __getattr__
member = self._get_member(self._get_interface(name), name)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bkbilly/venv/lib/python3.12/site-packages/dasbus/client/proxy.py", line 223, in _get_interface
raise AttributeError(
AttributeError: DBus object has no attribute 'PlayPause'. Is there another way of sending this PlayPause command? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
It seems that I made a mistake and it needed the interface, but it still doesn't work: from dasbus.connection import SessionMessageBus
bus = SessionMessageBus()
proxy = bus.get_proxy(
service_name="org.mpris.MediaPlayer2.chromium.instance5082",
object_path="/org/mpris/MediaPlayer2",
interface_name="org.mpris.MediaPlayer2.Player",
)
proxy.PlayPause() But I still get an error: Traceback (most recent call last):
File "/home/bkbilly/Documents/dbus_mediaplayer.py", line 9, in <module>
proxy.PlayPause()
^^^^^^^^^^^^^^^
File "/home/bkbilly/venv/lib/python3.12/site-packages/dasbus/client/proxy.py", line 161, in __getattr__
member = self._get_member(self._get_interface(name), name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bkbilly/venv/lib/python3.12/site-packages/dasbus/client/proxy.py", line 126, in _get_member
return self._create_member(*key)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bkbilly/venv/lib/python3.12/site-packages/dasbus/client/proxy.py", line 149, in _create_member
raise AttributeError(str(e)) from None
AttributeError: DBus specification has no member 'org.mpris.MediaPlayer2.Player.PlayPause'. |
Beta Was this translation helpful? Give feedback.
-
After a lot of hours searching, I managed to find how to send a message call to DBus. Apparently when it's using the interface_name, it doesn't get the attribute calls automatically so it has to be done manually. This is the service call I used to control the media: from dasbus.connection import SessionMessageBus
from gi.repository import Gio
bus = SessionMessageBus()
bus.connection.call(
bus_name="org.mpris.MediaPlayer2.chromium.instance4730",
object_path="/org/mpris/MediaPlayer2",
interface_name="org.mpris.MediaPlayer2.Player",
method_name="PlayPause",
parameters=None,
reply_type=None,
flags=Gio.DBusCallFlags.NONE,
timeout_msec=1,
cancellable=None,
callback=None,
user_data=None,
) If I could make a suggestion, it would be to add this to the documentation under the examples for others to use. |
Beta Was this translation helpful? Give feedback.
After a lot of hours searching, I managed to find how to send a message call to DBus. Apparently when it's using the interface_name, it doesn't get the attribute calls automatically so it has to be done manually.
This is the service call I used to control the media: