Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

loading Soundfont player #70

Closed
Treefrog74 opened this issue Jan 26, 2020 · 2 comments
Closed

loading Soundfont player #70

Treefrog74 opened this issue Jan 26, 2020 · 2 comments

Comments

@Treefrog74
Copy link

Hello -
Please forgive my ignorance as I am relatively new to programming.

I am using the Soundfont player for a sketch in p5.js. I have created a play button to play my song after I have chosen my instruments. If I press the play button right away, the sound is a bit choppy. If I wait a second or two, it's fine. Is there a simple line I can add that will prevent the song from playing until the sound is fully loaded?
i.e. if (instrument.isLoaded()){instrument.play}
Thanks

@danigb
Copy link
Owner

danigb commented Jan 26, 2020

Hi @Treefrog74

I don't know what exactly can be the cause of your problem. In theory, if you write this:

Soundfont.instrument(new AudioContext(), 'acoustic_grand_piano').then(function (piano) {
  // 👉 at this point the piano is fully loaded
  piano.play('C4')
})

Nowadays, starting audio context is a little bit tricky. I think your problem could be related to that: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes

If so, this may help: https://github.com/JohnWeisz/web-audio-api-autostart

hope it works! good luck 🤞

@danigb danigb closed this as completed Jan 26, 2020
@Treefrog74
Copy link
Author

Treefrog74 commented Jan 27, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants