File: mpris.py

package info (click to toggle)
dbus-fast 3.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,804 kB
  • sloc: python: 9,997; xml: 39; makefile: 29; sh: 5
file content (46 lines) | stat: -rwxr-xr-x 1,319 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
import os
import sys

sys.path.append(os.path.abspath(os.path.dirname(__file__) + "/.."))

import asyncio

from dbus_fast.aio import MessageBus


async def main():
    bus = await MessageBus().connect()
    # the introspection xml would normally be included in your project, but
    # this is convenient for development
    introspection = await bus.introspect(
        "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2"
    )

    obj = bus.get_proxy_object(
        "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2", introspection
    )
    player = obj.get_interface("org.mpris.MediaPlayer2.Player")
    properties = obj.get_interface("org.freedesktop.DBus.Properties")

    # call methods on the interface (this causes the media player to play)
    await player.call_play()

    volume = await player.get_volume()
    print(f"current volume: {volume}, setting to 0.5")

    await player.set_volume(0.5)

    # listen to signals
    def on_properties_changed(
        interface_name, changed_properties, invalidated_properties
    ):
        for changed, variant in changed_properties.items():
            print(f"property changed: {changed} - {variant.value}")

    properties.on_properties_changed(on_properties_changed)

    await bus.wait_for_disconnect()


asyncio.run(main())