結果を表示する
元にもどす
<html> <meta charset="utf-8"> <style> button{height:30px; font-size:12px; font-weight:bold; color:gray;} button:hover{height:30px; font-size:12px; font-weight:bold; color:black; background-color:white;} </style> <button id="ぼたん">Sound ▶︎</button> <button id="止まる">|| Pause ||</button> <hr> <script> let 音=new AudioContext(); let 波形; let 演奏=false; document.querySelector("#ぼたん").addEventListener("click",()=> {if(演奏)return; 波形=音.createOscillator(); 波形.type="sine"; 波形.frequency.setValueAtTime(220,音.currentTime); 波形.connect(音.destination); 波形.start(); 演奏=true}); document.querySelector("#止まる").addEventListener("click",()=> {波形?.stop(); 演奏=false;}); </script> </html>