connect source to output destination when used as chrome extension to keep audio playing
This commit is contained in:
parent
545ea15c9a
commit
2fe3ca0188
1 changed files with 21 additions and 0 deletions
|
|
@ -29,6 +29,8 @@ let selectedMicrophoneId = null;
|
||||||
let serverUseAudioWorklet = null;
|
let serverUseAudioWorklet = null;
|
||||||
let configReadyResolve;
|
let configReadyResolve;
|
||||||
const configReady = new Promise((r) => (configReadyResolve = r));
|
const configReady = new Promise((r) => (configReadyResolve = r));
|
||||||
|
let outputAudioContext = null;
|
||||||
|
let audioSource = null;
|
||||||
|
|
||||||
waveCanvas.width = 60 * (window.devicePixelRatio || 1);
|
waveCanvas.width = 60 * (window.devicePixelRatio || 1);
|
||||||
waveCanvas.height = 30 * (window.devicePixelRatio || 1);
|
waveCanvas.height = 30 * (window.devicePixelRatio || 1);
|
||||||
|
|
@ -511,6 +513,15 @@ async function startRecording() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
outputAudioContext = new (window.AudioContext || window.webkitAudioContext)();
|
||||||
|
audioSource = outputAudioContext.createMediaStreamSource(stream);
|
||||||
|
audioSource.connect(outputAudioContext.destination);
|
||||||
|
} catch (audioError) {
|
||||||
|
console.warn('could not preserve system audio:', audioError);
|
||||||
|
}
|
||||||
|
|
||||||
statusText.textContent = "Using tab audio capture.";
|
statusText.textContent = "Using tab audio capture.";
|
||||||
} catch (tabError) {
|
} catch (tabError) {
|
||||||
console.log('Tab capture not available, falling back to microphone', tabError);
|
console.log('Tab capture not available, falling back to microphone', tabError);
|
||||||
|
|
@ -659,6 +670,16 @@ async function stopRecording() {
|
||||||
audioContext = null;
|
audioContext = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (audioSource) {
|
||||||
|
audioSource.disconnect();
|
||||||
|
audioSource = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outputAudioContext && outputAudioContext.state !== "closed") {
|
||||||
|
outputAudioContext.close()
|
||||||
|
outputAudioContext = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (animationFrame) {
|
if (animationFrame) {
|
||||||
cancelAnimationFrame(animationFrame);
|
cancelAnimationFrame(animationFrame);
|
||||||
animationFrame = null;
|
animationFrame = null;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue