From efbcbc599fd7c435fa4a5c24a7574e4a3056693f Mon Sep 17 00:00:00 2001 From: imonlinux <39863321+imonlinux@users.noreply.github.com> Date: Sat, 11 Oct 2025 15:34:09 -0700 Subject: [PATCH] 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. --- linux_voice_assistant/mpv_player.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/linux_voice_assistant/mpv_player.py b/linux_voice_assistant/mpv_player.py index ef55283..2c658a7 100644 --- a/linux_voice_assistant/mpv_player.py +++ b/linux_voice_assistant/mpv_player.py @@ -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()