mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-09 17:51:46 +00:00
fix(exponential-volume): volume desync bug (#3787)
Co-authored-by: JellyBrick <shlee1503@naver.com>
This commit is contained in:
@ -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);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user