Implement Volume Persistence

Updates the MpvMediaPlayer constructor (__init__) to accept an initial_volume parameter.

This allows the volume to be set immediately when the mpv process is created, applying the saved setting at startup.
This commit is contained in:
imonlinux
2025-10-11 15:34:09 -07:00
committed by GitHub
parent 6e63111e63
commit efbcbc599f
+6 -2
View File
@@ -1,4 +1,3 @@
# linux_voice_assistant/mpv_player.py
"""
Media player using mpv in a subprocess.
@@ -103,7 +102,9 @@ def _select_backend(player: MPV, device: Optional[str], env_ao: Optional[str]) -
class MpvMediaPlayer:
def __init__(self, device: Optional[str] = None, watchdog_sec: float = 0.0) -> None:
def __init__(
self, device: Optional[str] = None, watchdog_sec: float = 0.0, initial_volume: float = 1.0
) -> None:
self.player = MPV(video=False, terminal=False, log_handler=self._mpv_log)
_set_player_opt(self.player, "audio-samplerate", 44100)
@@ -116,6 +117,9 @@ class MpvMediaPlayer:
env_ao = _normalize_env_ao(os.environ.get("LVA_AO"))
self._ao, self._audio_device = _select_backend(self.player, device, env_ao)
# Set initial volume from preferences
self.set_volume(int(initial_volume * 100))
self.is_playing: bool = False
self._done_callback: Optional[Callable[[], None]] = None
self._done_callback_lock = Lock()