Click then start

This commit is contained in:
Abdussamed ULUTAŞ 2022-12-14 00:01:27 +03:00
parent 1065b3385b
commit e776f86f8a
1 changed files with 17 additions and 0 deletions

17
main.js
View File

@ -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)
};