mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-22 19:18:31 +00:00
Merge pull request #399 from tidalcycles/awaitable-audio-init
can now await initAudio + initAudioOnFirstClick
This commit is contained in:
commit
c6491a3ccd
@ -126,21 +126,24 @@ function getWorklet(ac, processor, params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this function should be called on first user interaction (to avoid console warning)
|
// this function should be called on first user interaction (to avoid console warning)
|
||||||
export function initAudio() {
|
export async function initAudio() {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
try {
|
try {
|
||||||
getAudioContext().resume();
|
await getAudioContext().resume();
|
||||||
loadWorklets();
|
await loadWorklets();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('could not load AudioWorklet effects coarse, crush and shape', err);
|
console.warn('could not load AudioWorklet effects coarse, crush and shape', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initAudioOnFirstClick() {
|
export async function initAudioOnFirstClick() {
|
||||||
document.addEventListener('click', function listener() {
|
return new Promise((resolve) => {
|
||||||
initAudio();
|
document.addEventListener('click', async function listener() {
|
||||||
document.removeEventListener('click', listener);
|
await initAudio();
|
||||||
|
resolve();
|
||||||
|
document.removeEventListener('click', listener);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user