From 34e2c8a2bdff902da0d8e245162045318947fb50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20de=20la=20Martini=C3=A8re?= Date: Wed, 3 Apr 2024 20:13:53 +0200 Subject: [PATCH] Attempt to make custom audio outputs work again --- .../AudioOutputSelect/AudioOutputSelect.tsx | 12 ++++++------ src/lib/player.ts | 12 ++++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/components/AudioOutputSelect/AudioOutputSelect.tsx b/src/components/AudioOutputSelect/AudioOutputSelect.tsx index 2d0ca8043..28472a095 100644 --- a/src/components/AudioOutputSelect/AudioOutputSelect.tsx +++ b/src/components/AudioOutputSelect/AudioOutputSelect.tsx @@ -18,12 +18,12 @@ export default function AudioOutputSelect(props: Props) { useEffect(() => { const refreshDevices = async () => { try { - // Webkit sucks, we need to request permissions for inputs, when we only - // need outputs - // const test = await navigator.mediaDevices.getUserMedia({ - // audio: true, - // video: false, - // }); + // This will display a popup to users asking them to give microphone access, + // which is lame because we only need outputs. + // Does not work on macOS/linux for now. + await navigator.mediaDevices.getUserMedia({ + audio: true, + }); const devices = await navigator.mediaDevices.enumerateDevices(); const audioDevices = devices.filter( (device) => device.kind === 'audiooutput' && device.deviceId !== '', diff --git a/src/lib/player.ts b/src/lib/player.ts index 971afdf56..9625365fe 100644 --- a/src/lib/player.ts +++ b/src/lib/player.ts @@ -37,10 +37,14 @@ class Player { this.track = null; this.audio.defaultPlaybackRate = mergedOptions.playbackRate; - // eslint-disable-next-line - // @ts-ignore - // TODO: - // this.audio.setSinkId(mergedOptions.audioOutputDevice); + + // FIXME: this will not do anything unless we recall getUserMedia() + if ('setSinkId' in this.audio) { + // eslint-disable-next-line + // @ts-ignore + this.audio.setSinkId(mergedOptions.audioOutputDevice); + } + this.audio.playbackRate = mergedOptions.playbackRate; this.audio.volume = mergedOptions.volume; this.audio.muted = mergedOptions.muted;