Skip to content

First note starting on "currentTime+1" : it fails #75

Answered by danigb
rogerio-saldanha asked this question in Q&A
Discussion options

You must be logged in to vote

This works for me:

<html>
  <body>
    <button id="btn">play</button>
  </body>
  <script type="module">
    import { SplendidGrandPiano } from "https://unpkg.com/smplr/dist/index.mjs"; 
    const context = new AudioContext(); 
    const piano = new SplendidGrandPiano(context); 

    document.getElementById("btn").onclick = () => {
      context.resume(); // enable audio context after a user interaction
      const now = context.currentTime
      piano.start({ note: 60, velocity: 80, time: now + 1 }); // play the note after 1 second
    };
  </script>
</html>

So I guess the problem is that you didn't resume the audio context first.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rogerio-saldanha
Comment options

Answer selected by rogerio-saldanha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants