From e776f86f8a974fc95b8e0ed7d4765a6a0d9b8829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdussamed=20ULUTA=C5=9E?= Date: Wed, 14 Dec 2022 00:01:27 +0300 Subject: [PATCH] Click then start --- main.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main.js b/main.js index b7de52a..26d8275 100644 --- a/main.js +++ b/main.js @@ -74,9 +74,17 @@ fetch("Contra.webm").then(e => e.arrayBuffer()).then(e => { source.connect(analyser); source.connect(audioCtx.destination); +let started = false; canvas.addEventListener("click",async ()=>{ await audioCtx.resume(); source.start(); + started = true; +},{once:true}) + +canvas.addEventListener("touchend",async ()=>{ + await audioCtx.resume(); + source.start(); + started = true; },{once:true}) analyser.fftSize = 2 ** 13; @@ -125,6 +133,15 @@ function RenderWave() ctx.lineTo(width, height / 2); ctx.stroke(); + if(!started) + { + ctx.font = ((width * .05)|0)+"px ubuntu"; + ctx.textBaseline = "middle"; + ctx.textAlign = "center"; + ctx.fillStyle = "black"; + ctx.fillText("Başlatmak için dokunun", width / 2, height / 2); + } + requestAnimationFrame(RenderWave) };