danigb / soundfont-player

Quick soundfont loader and player for browser
MIT License
453 stars 60 forks source link

loading Soundfont player #70

Closed Treefrog74 closed 4 years ago

Treefrog74 commented 4 years ago

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 commented 4 years ago

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 ๐Ÿคž

Treefrog74 commented 4 years ago

Thanks for responding! I really appreciate it.

I will look a little deeper with your suggestions. If I canโ€™t get it working Iโ€™ll send you a link to the sketch Iโ€™m working on.

Leo

On Jan 26, 2020, at 2:23 PM, danigb notifications@github.com wrote:

Hi @Treefrog74 https://github.com/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 https://developers.google.com/web/updates/2017/09/autoplay-policy-changes If so, this may help: https://github.com/JohnWeisz/web-audio-api-autostart https://github.com/JohnWeisz/web-audio-api-autostart hope it works! good luck ๐Ÿคž

โ€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/danigb/soundfont-player/issues/70?email_source=notifications&email_token=AOLRWD6GE3UHHKJLAGJMFO3Q7X5O3A5CNFSM4KLTZGH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ56I2I#issuecomment-578544745, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOLRWD2LCUH7RA7VFZLH5LLQ7X5O3ANCNFSM4KLTZGHQ.