From a44071fedd194716ffa1886b4718fd6c0eedfd2f Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Sat, 24 Aug 2024 20:13:30 -0700 Subject: [PATCH] add error checking for set sink id (case of no devices at all) --- src/renderer/components/audio-player/index.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/renderer/components/audio-player/index.tsx b/src/renderer/components/audio-player/index.tsx index 140da56d..7f022f2e 100644 --- a/src/renderer/components/audio-player/index.tsx +++ b/src/renderer/components/audio-player/index.tsx @@ -266,12 +266,16 @@ export const AudioPlayer = forwardRef( // 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 { - // @ts-ignore - webAudio.context.setSinkId(''); + try { + if (audioDeviceId !== 'default') { + // @ts-ignore + webAudio.context.setSinkId(audioDeviceId); + } else { + // @ts-ignore + webAudio.context.setSinkId(''); + } + } catch (error) { + toast.error({ message: `Error setting sink: ${(error as Error).message}` }); } } }, [audioDeviceId, webAudio]);