mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-21 18:48:36 +00:00
suspend and close exisiting audio context
This commit is contained in:
parent
63066937e9
commit
8f56ef6507
@ -30,11 +30,12 @@ let audioContext;
|
|||||||
|
|
||||||
export const setDefaultAudioContext = () => {
|
export const setDefaultAudioContext = () => {
|
||||||
audioContext = new AudioContext();
|
audioContext = new AudioContext();
|
||||||
|
return audioContext;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAudioContext = () => {
|
export const getAudioContext = () => {
|
||||||
if (!audioContext) {
|
if (!audioContext) {
|
||||||
setDefaultAudioContext();
|
return setDefaultAudioContext();
|
||||||
}
|
}
|
||||||
return audioContext;
|
return audioContext;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -19,10 +19,14 @@ export const getAudioDevices = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const setAudioDevice = async (id) => {
|
export const setAudioDevice = async (id) => {
|
||||||
const audioCtx = getAudioContext();
|
let audioCtx = getAudioContext();
|
||||||
if (audioCtx.sinkId === id) {
|
if (audioCtx.sinkId === id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
await audioCtx.suspend();
|
||||||
|
await audioCtx.close();
|
||||||
|
audioCtx = setDefaultAudioContext();
|
||||||
|
await audioCtx.resume();
|
||||||
const isValidID = (id ?? '').length > 0;
|
const isValidID = (id ?? '').length > 0;
|
||||||
if (isValidID) {
|
if (isValidID) {
|
||||||
try {
|
try {
|
||||||
@ -30,9 +34,6 @@ export const setAudioDevice = async (id) => {
|
|||||||
} catch {
|
} catch {
|
||||||
logger('failed to set audio interface', 'warning');
|
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();
|
initializeAudioOutput();
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user