Skip to content

Commit

Permalink
[bugfix]: SAFARI WHY. Use GainNode volume instead for volume control
Browse files Browse the repository at this point in the history
  • Loading branch information
kgarner7 committed Jan 25, 2024
1 parent 669c2a9 commit 4a953e4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/renderer/components/audio-player/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const AudioPlayer = forwardRef(
const calculateReplayGain = useCallback(
(song: Song): number => {
if (playback.replayGainMode === 'no') {
return 1;
return volume;
}

let gain: number | undefined;
Expand All @@ -99,7 +99,7 @@ export const AudioPlayer = forwardRef(
gain = playback.replayGainFallbackDB;

if (!gain) {
return 1;
return volume;
}
}

Expand All @@ -116,13 +116,14 @@ export const AudioPlayer = forwardRef(
if (playback.replayGainClip) {
return Math.min(expectedGain, 1 / peak);
}
return expectedGain;
return expectedGain * volume;
},
[
playback.replayGainClip,
playback.replayGainFallbackDB,
playback.replayGainMode,
playback.replayGainPreampDB,
volume,
],
);

Expand Down Expand Up @@ -311,6 +312,9 @@ export const AudioPlayer = forwardRef(
[player2Source, webAudio],
);

// Bugfix for Safari: rather than use the `<audio>` volume (which doesn't work),
// use the GainNode to scale the volume. In this case, for compatibility with
// other browsers, set the `<audio>` volume to 1
return (
<>
<ReactPlayer
Expand All @@ -324,7 +328,7 @@ export const AudioPlayer = forwardRef(
playing={currentPlayer === 1 && status === PlayerStatus.PLAYING}
progressInterval={isTransitioning ? 10 : 250}
url={player1?.streamUrl || EMPTY_SOURCE}
volume={volume}
volume={webAudio ? 1 : volume}
width={0}
onEnded={handleOnEnded}
onProgress={
Expand All @@ -343,7 +347,7 @@ export const AudioPlayer = forwardRef(
playing={currentPlayer === 2 && status === PlayerStatus.PLAYING}
progressInterval={isTransitioning ? 10 : 250}
url={player2?.streamUrl || EMPTY_SOURCE}
volume={volume}
volume={webAudio ? 1 : volume}
width={0}
onEnded={handleOnEnded}
onProgress={
Expand Down

0 comments on commit 4a953e4

Please sign in to comment.