From 23013cddb97cac6d7d1c1611d052f393f597ed7b Mon Sep 17 00:00:00 2001 From: Benjas333 <67520048+Benjas333@users.noreply.github.com> Date: Fri, 5 Sep 2025 05:53:07 -0600 Subject: [PATCH] fix(exponential-volume): volume desync bug (#3787) Co-authored-by: JellyBrick --- src/plugins/exponential-volume/index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/plugins/exponential-volume/index.ts b/src/plugins/exponential-volume/index.ts index 86782984..19174707 100644 --- a/src/plugins/exponential-volume/index.ts +++ b/src/plugins/exponential-volume/index.ts @@ -1,6 +1,8 @@ import { createPlugin } from '@/utils'; import { t } from '@/i18n'; +import type { YoutubePlayer } from '@/types/youtube-player'; + export default createPlugin({ name: () => t('plugins.exponential-volume.name'), description: () => t('plugins.exponential-volume.description'), @@ -9,7 +11,16 @@ export default createPlugin({ enabled: false, }, renderer: { - onPlayerApiReady() { + onPlayerApiReady(playerApi) { + const syncVolume = (playerApi: YoutubePlayer) => { + if (playerApi.getPlayerState() === 3) { + setTimeout(() => syncVolume(playerApi), 0); + return; + } + + playerApi.setVolume(playerApi.getVolume()); + }; + // "YouTube Music fix volume ratio 0.4" by Marco Pfeiffer // https://greasyfork.org/en/scripts/397686-youtube-music-fix-volume-ratio/ @@ -48,6 +59,7 @@ export default createPlugin({ propertyDescriptor?.set?.call(this, lowVolume); }, }); + syncVolume(playerApi); }, }, });