fix(exponential-volume): volume desync bug (#3787)

Co-authored-by: JellyBrick <shlee1503@naver.com>
This commit is contained in:
Benjas333
2025-09-05 05:53:07 -06:00
committed by GitHub
parent 588b84ecd0
commit 23013cddb9

View File

@ -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);
},
},
});