constructor(container){ super() const loader = document.createElement('div') loader.id = 'loader' container.appendChild(loader) const loaderText = document.createElement('div') loaderText.id = 'loaderText' loaderText.textContent = 'loading' loader.appendChild(loaderText) const fill = document.createElement('div') fill.id = 'fill' loader.appendChild(fill) const fillText = document.createElement('div') fillText.id = 'fillText' fillText.textContent = 'loading' fill.appendChild(fillText) StartAudioContext(Tone.context, loader) this.loaded = false Buffer.on('load', () => { this.loaded = true fillText.innerHTML = '<div id="piano"></div> <div id="play">PLAY</div>' loader.classList.add('clickable') loader.addEventListener('click', () => { this.emit('click') }) }) Buffer.on('progress', (prog) => { fill.style.width = `${(prog * 100).toFixed(2)}%` }) }
import StartAudioContext from 'startaudiocontext'; import platform from 'platform'; let AUDIO_CONTEXT; if (platform.name !== 'IE') { AUDIO_CONTEXT = new (window.AudioContext || window.webkitAudioContext)(); StartAudioContext(AUDIO_CONTEXT); } /** * Wrap browser AudioContext because we shouldn't create more than one * @return {AudioContext} The singleton AudioContext */ export default function () { return AUDIO_CONTEXT; }