Rockbox open source high quality audio player as a Music Player Daemon
mpris
rockbox
mpd
libadwaita
audio
rust
zig
deno
1"""05 — Volume control.
2
3Read current volume (with min/max range) and bump it up by one step.
4
5 uv run python examples/05_volume_control.py # show + step up
6 uv run python examples/05_volume_control.py -3 # step down 3
7"""
8
9from __future__ import annotations
10
11import asyncio
12import sys
13
14from _client import create_client # type: ignore[import-not-found]
15
16
17async def main(delta: int) -> None:
18 async with create_client() as client:
19 before = await client.sound.get_volume()
20 rng = before.max - before.min
21 filled = round(((before.volume - before.min) / rng) * 20) if rng > 0 else 0
22 bar = "█" * filled + "░" * max(0, 20 - filled)
23
24 print(f"Volume: {before.volume} dB (range {before.min} … {before.max})")
25 print(f" {bar}")
26
27 after = await client.sound.adjust_volume(delta)
28 sign = f"+{delta}" if delta >= 0 else str(delta)
29 print(f"\nAdjusted by {sign} → {after} dB")
30
31
32if __name__ == "__main__":
33 delta = int(sys.argv[1]) if len(sys.argv) > 1 else 1
34 asyncio.run(main(delta))