mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-24 12:57:55 +02:00
fix replaygain volume jump (#1576)
This commit is contained in:
@@ -450,33 +450,36 @@ export function WebPlayer() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!webAudio) return;
|
if (!webAudio || !player1 || !player1Source) return;
|
||||||
|
|
||||||
if (player1 && player1Source && num === 1) {
|
|
||||||
const newGain = calculateReplayGain(player1);
|
const newGain = calculateReplayGain(player1);
|
||||||
|
|
||||||
// This error SHOULD never happen, as calculateReplayGain is expected to
|
// Apply per player slot whenever its song/source is ready so pre-started
|
||||||
// always return a real value. However, to prevent app crash, check this just in case
|
// inactive players have correct gain before gapless/crossfade transitions.
|
||||||
try {
|
try {
|
||||||
webAudio.gains[0].gain.setValueAtTime(Math.max(0, newGain), 0);
|
webAudio.gains[0].gain.setValueAtTime(
|
||||||
|
Math.max(0, newGain),
|
||||||
|
webAudio.context.currentTime,
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error setting gain', error);
|
console.error('Error setting gain', error);
|
||||||
}
|
}
|
||||||
}
|
}, [calculateReplayGain, player1, player1Source, webAudio]);
|
||||||
}, [calculateReplayGain, num, player1, player1Source, volume, webAudio]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!webAudio) return;
|
if (!webAudio || !player2 || !player2Source) return;
|
||||||
|
|
||||||
if (player2 && player2Source && num === 2) {
|
|
||||||
const newGain = calculateReplayGain(player2);
|
const newGain = calculateReplayGain(player2);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
webAudio.gains[1].gain.setValueAtTime(Math.max(0, newGain), 0);
|
webAudio.gains[1].gain.setValueAtTime(
|
||||||
|
Math.max(0, newGain),
|
||||||
|
webAudio.context.currentTime,
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error setting gain', error);
|
console.error('Error setting gain', error);
|
||||||
}
|
}
|
||||||
}
|
}, [calculateReplayGain, player2, player2Source, webAudio]);
|
||||||
}, [calculateReplayGain, num, player1, player2Source, player2, volume, webAudio]);
|
|
||||||
|
|
||||||
const player1Url = useSongUrl(player1, num === 1, transcode);
|
const player1Url = useSongUrl(player1, num === 1, transcode);
|
||||||
const player2Url = useSongUrl(player2, num === 2, transcode);
|
const player2Url = useSongUrl(player2, num === 2, transcode);
|
||||||
|
|||||||
Reference in New Issue
Block a user