mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-12 06:08:37 +00:00
Merge pull request #882 from daslyfe/audio_device_selection
bugfix: suspend and close exisiting audio context when changing interface
This commit is contained in:
commit
5150ec06dc
@ -30,11 +30,12 @@ let audioContext;
|
||||
|
||||
export const setDefaultAudioContext = () => {
|
||||
audioContext = new AudioContext();
|
||||
return audioContext;
|
||||
};
|
||||
|
||||
export const getAudioContext = () => {
|
||||
if (!audioContext) {
|
||||
setDefaultAudioContext();
|
||||
return setDefaultAudioContext();
|
||||
}
|
||||
return audioContext;
|
||||
};
|
||||
|
||||
@ -19,10 +19,14 @@ export const getAudioDevices = async () => {
|
||||
};
|
||||
|
||||
export const setAudioDevice = async (id) => {
|
||||
const audioCtx = getAudioContext();
|
||||
let audioCtx = getAudioContext();
|
||||
if (audioCtx.sinkId === id) {
|
||||
return;
|
||||
}
|
||||
await audioCtx.suspend();
|
||||
await audioCtx.close();
|
||||
audioCtx = setDefaultAudioContext();
|
||||
await audioCtx.resume();
|
||||
const isValidID = (id ?? '').length > 0;
|
||||
if (isValidID) {
|
||||
try {
|
||||
@ -30,9 +34,6 @@ export const setAudioDevice = async (id) => {
|
||||
} catch {
|
||||
logger('failed to set audio interface', 'warning');
|
||||
}
|
||||
} else {
|
||||
// reset the audio context and dont set the sink id if it is invalid AKA System Standard selection
|
||||
setDefaultAudioContext();
|
||||
}
|
||||
initializeAudioOutput();
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user