From 1de7e5cccea6984f33349d11a461fa5a73659740 Mon Sep 17 00:00:00 2001 From: HerozDotExe Date: Sun, 21 Sep 2025 19:23:56 +0200 Subject: [PATCH] feat: allow to play sound twice on dfferent device --- src/renderer/src/lib/audio.ts | 10 +- .../src/lib/components/DevicesSelector.svelte | 130 ++++++++++++++++++ src/renderer/src/lib/components/Footer.svelte | 94 +------------ .../src/lib/components/Results.svelte | 8 +- 4 files changed, 147 insertions(+), 95 deletions(-) create mode 100644 src/renderer/src/lib/components/DevicesSelector.svelte diff --git a/src/renderer/src/lib/audio.ts b/src/renderer/src/lib/audio.ts index da82302..67b4094 100644 --- a/src/renderer/src/lib/audio.ts +++ b/src/renderer/src/lib/audio.ts @@ -1,21 +1,29 @@ export class _Audio { src: string audio: HTMLAudioElement + secondaryAudio: HTMLAudioElement constructor(src: string) { this.src = src this.audio = new Audio(src) + this.secondaryAudio = new Audio(src) } play() { this.audio.play() + this.secondaryAudio.play() } stop() { this.audio.pause() + this.secondaryAudio.pause() this.audio.remove() + this.secondaryAudio.remove() } - setOuputDevice(id: string) { + setMainOuputDevice(id: string) { this.audio.setSinkId(id) } + setSecondaryOuputDevice(id: string) { + this.secondaryAudio.setSinkId(id) + } } diff --git a/src/renderer/src/lib/components/DevicesSelector.svelte b/src/renderer/src/lib/components/DevicesSelector.svelte new file mode 100644 index 0000000..238dd97 --- /dev/null +++ b/src/renderer/src/lib/components/DevicesSelector.svelte @@ -0,0 +1,130 @@ + + + + + + + Select main audio device + Usually you should select "CABLE Input" + + + {#each kinds as kind (kind)} +
+ + +
+ {/each} +
+ + + {mainTriggerContent} + + + + Devices + {#each devices as device (`${device.deviceId}`)} + + {device.label} + + {/each} + + + +
+ + Select secondary audio device + Usually you should your headset + + + {#each kinds as secondaryKind (secondaryKind)} +
+ + +
+ {/each} +
+ + + {secondaryTriggerContent} + + + + Devices + {#each devices as device (`${device.deviceId}`)} + + {device.label} + + {/each} + + + + + + +
+
diff --git a/src/renderer/src/lib/components/Footer.svelte b/src/renderer/src/lib/components/Footer.svelte index c1b52ca..0b81305 100644 --- a/src/renderer/src/lib/components/Footer.svelte +++ b/src/renderer/src/lib/components/Footer.svelte @@ -1,95 +1,7 @@ - diff --git a/src/renderer/src/lib/components/Results.svelte b/src/renderer/src/lib/components/Results.svelte index 8807bc0..4dcf106 100644 --- a/src/renderer/src/lib/components/Results.svelte +++ b/src/renderer/src/lib/components/Results.svelte @@ -7,17 +7,19 @@ let sound: _Audio function play(src: string): void { - if (!localStorage.getItem('output_device_id')) { + if (!localStorage.getItem('output_main_device_id')) { return alert('Please select an audio device to ouput sounds.') } if (sound) { sound.stop() } sound = new _Audio(src) - sound.setOuputDevice(localStorage.getItem('output_device_id')) + sound.setMainOuputDevice(localStorage.getItem('output_main_device_id')) + if (localStorage.getItem('output_secondary_device_id')) { + sound.setSecondaryOuputDevice(localStorage.getItem('output_secondary_device_id')) + } sound.play() } - onMount(async () => { states.sounds = await window.api.search() })