init audio on first click to remove warning

This commit is contained in:
Felix Roos 2022-11-10 22:03:23 +01:00
parent 00550ddab5
commit b688b8921a
2 changed files with 19 additions and 6 deletions

View File

@ -176,14 +176,25 @@ function getWorklet(ac, processor, params) {
return node;
}
if (typeof window !== 'undefined') {
try {
loadWorklets();
} catch (err) {
console.warn('could not load AudioWorklet effects coarse, crush and shape', err);
// this function should be called on first user interaction (to avoid console warning)
export function initAudio() {
if (typeof window !== 'undefined') {
try {
getAudioContext().resume();
loadWorklets();
} catch (err) {
console.warn('could not load AudioWorklet effects coarse, crush and shape', err);
}
}
}
export function initAudioOnFirstClick() {
document.addEventListener('click', function listener() {
initAudio();
document.removeEventListener('click', listener);
});
}
function gainNode(value) {
const node = getAudioContext().createGain();
node.gain.value = value;

View File

@ -18,7 +18,9 @@ import { controls, evalScope, logger } from '@strudel.cycles/core';
import { createClient } from '@supabase/supabase-js';
import { nanoid } from 'nanoid';
import { useStrudel } from '@strudel.cycles/react';
import { webaudioOutput } from '@strudel.cycles/webaudio';
import { webaudioOutput, initAudioOnFirstClick } from '@strudel.cycles/webaudio';
initAudioOnFirstClick();
// Create a single supabase client for interacting with your database
const supabase = createClient(