mk-fg / python-pulse-control

Python high-level interface and ctypes-based bindings for PulseAudio (libpulse)
https://pypi.org/project/pulsectl/
MIT License
170 stars 36 forks source link

Get default sink #81

Closed Core447 closed 5 months ago

Core447 commented 5 months ago

I can't find a way to get the active sink/source set by `default_set'. Am I missing something or is it really not available right now?

mk-fg commented 5 months ago

Hi.

For some reason these are returned in pulse.server_info() with libpulse, and don't have their own corresponding get-methods.

You can use names from there with get_sink_by_name / get_source_by_name to get sink/source info, e.g.:

with pulsectl.Pulse() as pulse:
  si = pulse.server_info()
  print([si, pulse.get_sink_by_name(si.default_sink_name)])

Not very intuitive though, and maybe indeed worth adding couple methods to get default sink/source from that info specifically.

mk-fg commented 5 months ago

Added get methods next to set for sinks/sources in 34c4ba9 / 24.4.0, though if you want both at once, might be more efficient to call server_info() once yourself instead. Thanks for bringing it up.

Core447 commented 5 months ago

Ok, perfect, thanks