From af69a584183c2a08be1222bc7418fb898b8ac60a Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Mon, 19 Aug 2024 22:38:51 -0700 Subject: [PATCH] [bugfix]: use chrome-specific implementation for web audio sink --- src/renderer/components/audio-player/index.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/renderer/components/audio-player/index.tsx b/src/renderer/components/audio-player/index.tsx index 85262054..bf88bf57 100644 --- a/src/renderer/components/audio-player/index.tsx +++ b/src/renderer/components/audio-player/index.tsx @@ -262,16 +262,19 @@ export const AudioPlayer = forwardRef( ); useEffect(() => { - if (isElectron()) { - if (audioDeviceId) { - player1Ref.current?.getInternalPlayer()?.setSinkId(audioDeviceId); - player2Ref.current?.getInternalPlayer()?.setSinkId(audioDeviceId); + // Not standard, just used in chromium-based browsers. See + // https://developer.chrome.com/blog/audiocontext-setsinkid/. + // If the isElectron() check is every removed, fix this. + if (isElectron() && webAudio && 'setSinkId' in webAudio.context) { + if (audioDeviceId !== 'default') { + // @ts-ignore + webAudio.context.setSinkId(audioDeviceId); } else { - player1Ref.current?.getInternalPlayer()?.setSinkId(''); - player2Ref.current?.getInternalPlayer()?.setSinkId(''); + // @ts-ignore + webAudio.context.setSinkId(''); } } - }, [audioDeviceId]); + }, [audioDeviceId, webAudio]); useEffect(() => { if (webAudio && player1Source && player1 && currentPlayer === 1) {