Skip to content

Instantly share code, notes, and snippets.

@dasl-
Created July 23, 2021 01:52
Show Gist options
  • Save dasl-/0097abd4435218a05820f22056b32a6e to your computer and use it in GitHub Desktop.
Save dasl-/0097abd4435218a05820f22056b32a6e to your computer and use it in GitHub Desktop.
from dbus_next.message import Message, MessageType
from dbus_next.aio import MessageBus
import asyncio
import json
import time
loop = asyncio.get_event_loop()
# sending messages to omxplayer via dbus with
# https://github.com/altdesktop/python-dbus-next
async def main():
dbus_addr_file_path = "/tmp/omxplayerdbus.pi"
dbus_addr_file = open(dbus_addr_file_path)
address = dbus_addr_file.read().strip()
bus = await MessageBus(bus_address=address).connect()
while True:
start = time.time()
reply = await bus.call(
Message(
destination='org.mpris.MediaPlayer2.omxplayer',
path='/org/mpris/MediaPlayer2',
interface='org.freedesktop.DBus.Properties',
member='Set',
signature='ssd',
body=['org.mpris.MediaPlayer2.Player', 'Volume', 1.0]
)
)
if reply.message_type == MessageType.ERROR:
raise Exception(reply.body[0])
print(json.dumps(reply.body[0], indent=2))
elapsed_ms = (time.time() - start) * 1000
print(f"Sending dbus msg took {elapsed_ms} ms")
loop.run_until_complete(main())
@dasl-
Copy link
Author

dasl- commented Jul 23, 2021

timing data (it's slow):

 % python3 dbusnext.py
1.0
Sending dbus msg took 1770.0886726379395 ms
1.0
Sending dbus msg took 1618.9343929290771 ms
1.0
Sending dbus msg took 881.0429573059082 ms
1.0
Sending dbus msg took 1829.7810554504395 ms
1.0
Sending dbus msg took 1548.4654903411865 ms
1.0
Sending dbus msg took 1621.260643005371 ms
1.0
Sending dbus msg took 1091.1297798156738 ms
1.0
Sending dbus msg took 1503.690242767334 ms
1.0
Sending dbus msg took 1329.3845653533936 ms
1.0
Sending dbus msg took 1126.4171600341797 ms
1.0
Sending dbus msg took 2084.6731662750244 ms
1.0
Sending dbus msg took 3126.0986328125 ms
1.0
Sending dbus msg took 3588.442325592041 ms
1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment