Update mpv_player.py to support PipeWire
Updated the mpv_player.py to support PipeWire native devices (pipewire/default) instead of using the pipewire-pulse compatibility.
This commit is contained in:
@@ -41,27 +41,67 @@ class MpvMediaPlayer:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Normalize/select backend and device
|
# Normalize/select backend and device
|
||||||
ao = None
|
ao = None
|
||||||
norm = None
|
norm = None
|
||||||
|
|
||||||
|
# Helper to try candidates in order
|
||||||
|
def _try_candidates(candidates):
|
||||||
|
nonlocal ao, norm
|
||||||
|
for cand_ao, cand_norm in candidates:
|
||||||
|
try:
|
||||||
|
self.player["ao"] = cand_ao
|
||||||
|
ao = cand_ao
|
||||||
|
norm = cand_norm
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
return False
|
||||||
|
|
||||||
if device:
|
if device:
|
||||||
d = device.strip()
|
d = device.strip()
|
||||||
if d.startswith("alsa/"):
|
if d.startswith("alsa/"):
|
||||||
ao = "alsa"; norm = d
|
ao = "alsa"; norm = d
|
||||||
elif d.startswith("pulse/"):
|
elif d.startswith("pulse/"):
|
||||||
ao = "pulse"; norm = d
|
ao = "pulse"; norm = d
|
||||||
|
elif d.startswith(("pipewire/", "pw/")):
|
||||||
|
ao = "pipewire"; norm = d.replace("pw/", "pipewire/", 1)
|
||||||
elif d == "default":
|
elif d == "default":
|
||||||
try:
|
# Preference order: env override -> PipeWire -> Pulse -> ALSA
|
||||||
self.player["ao"] = "pulse"; norm = "pulse/default"
|
order = []
|
||||||
except Exception:
|
if ao_env in {"pipewire","pulse","alsa"}:
|
||||||
try:
|
order.append((ao_env, f"{ao_env}/default"))
|
||||||
self.player["ao"] = "alsa"; norm = "alsa/default"
|
order.extend([
|
||||||
except Exception:
|
("pipewire", "pipewire/default"),
|
||||||
_LOGGER.warning("Neither Pulse nor ALSA available for 'default'")
|
("pulse", "pulse/default"),
|
||||||
|
("alsa", "alsa/default"),
|
||||||
|
])
|
||||||
|
_try_candidates(order)
|
||||||
|
if ao is None:
|
||||||
|
_LOGGER.warning("No suitable audio output (PipeWire/Pulse/ALSA) available for 'default'")
|
||||||
else:
|
else:
|
||||||
# Assume Pulse sink name if no prefix
|
# No explicit prefix: respect env override if set; otherwise prefer PipeWire, then Pulse, then ALSA
|
||||||
ao = "pulse"; norm = f"pulse/{d}"
|
tried = False
|
||||||
|
if ao_env in {"pipewire","pulse","alsa"}:
|
||||||
|
tried = _try_candidates([(ao_env, f"{ao_env}/{d if ao_env!='alsa' else 'default'}")])
|
||||||
|
if not tried:
|
||||||
|
_try_candidates([
|
||||||
|
("pipewire", f"pipewire/{d}"),
|
||||||
|
("pulse", f"pulse/{d}"),
|
||||||
|
("alsa", "alsa/default"),
|
||||||
|
])
|
||||||
|
else:
|
||||||
|
# No device specified: env override first (if valid), then PipeWire, Pulse, ALSA
|
||||||
|
order = []
|
||||||
|
if ao_env in {"pipewire","pulse","alsa"}:
|
||||||
|
order.append((ao_env, f"{ao_env}/default"))
|
||||||
|
order.extend([
|
||||||
|
("pipewire", "pipewire/default"),
|
||||||
|
("pulse", "pulse/default"),
|
||||||
|
("alsa", "alsa/default"),
|
||||||
|
])
|
||||||
|
_try_candidates(order)
|
||||||
|
|
||||||
if ao:
|
if ao:
|
||||||
try:
|
try:
|
||||||
@@ -76,6 +116,7 @@ class MpvMediaPlayer:
|
|||||||
_LOGGER.warning("Failed to set audio-device=%s", norm)
|
_LOGGER.warning("Failed to set audio-device=%s", norm)
|
||||||
|
|
||||||
# State
|
# State
|
||||||
|
|
||||||
self.is_playing: bool = False
|
self.is_playing: bool = False
|
||||||
self._done_callback: Optional[Callable[[], None]] = None
|
self._done_callback: Optional[Callable[[], None]] = None
|
||||||
self._done_callback_lock = Lock()
|
self._done_callback_lock = Lock()
|
||||||
|
|||||||
Reference in New Issue
Block a user