diff --git a/src/useAudioContext.tsx b/src/useAudioContext.tsx index 4a7c031c..92d5b48f 100644 --- a/src/useAudioContext.tsx +++ b/src/useAudioContext.tsx @@ -178,7 +178,13 @@ export function useAudioContext( if ( audioContext && "setSinkId" in audioContext && - !controlledAudioDevices + !controlledAudioDevices && + // Skip until a device is actually selected. audioOutputId is undefined + // before MediaDevices resolves (e.g. on the Tauri desktop webview, where + // the selected$ observable emits undefined first); setSinkId(undefined) + // throws "The provided value is not of type 'AudioSinkOptions'". The + // default device is represented by the empty string, which is still valid. + typeof audioOutputId === "string" ) { // https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/setSinkId // @ts-expect-error - setSinkId doesn't exist yet in types, maybe because it's not supported everywhere.