sounts
Version:
A tiny helper library for working with the web audio API written in TypeScript.
24 lines (23 loc) • 840 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createAudioContext = void 0;
/**
* Creates a new audio context and resumes it once the user interacts with the window (via click or keypress).
*
* @param options The options passed to the audio context.
* @returns A new AudioContext instance.
*/
function createAudioContext(options) {
const context = new AudioContext(options);
if (context.state === "suspended") {
const listener = () => {
context.resume();
window.removeEventListener("click", listener);
window.removeEventListener("keydown", listener);
};
window.addEventListener("click", listener);
window.addEventListener("keydown", listener);
}
return context;
}
exports.createAudioContext = createAudioContext;