surikov / webaudiofont

Use full GM set of musical instruments to play MIDI and single sounds or effects. Support for reverberation and equaliser. No plugins, no Flash. Pure HTML5 implementation compatible with desktop and mobile browser. See live examples.
https://surikov.github.io/webaudiofont/
GNU General Public License v3.0
891 stars 92 forks source link

Avoid Runtime Error when using OfflineAudioContext #63

Closed dannybullo closed 4 years ago

dannybullo commented 4 years ago

Hi! The first line of code of queueWaveTable() is

if (audioContext.state == 'suspended') { console.log('audioContext.resume'); audioContext.resume(); }

This works fine. However, there are cases where it is desired to use an OfflineAudioContext, such as Rendering/Exporting to a WAV file. I managed it to work fine. However, the following error is thrown:

Uncaught (in promise) DOMException: cannot resume an offline context that has not started

This is expected, as we should not use resume() in an OfflineAudioContext. A simple solution would be:

if (audioContext.state == 'suspended' && audioContext.constructor.name == "AudioContext") { console.log('audioContext.resume'); audioContext.resume(); }

What do you think?

Thanks! Danny Bullo

surikov commented 4 years ago

fixed

dannybullo commented 4 years ago

Thanks @surikov