work.suroh.tk/js/audio.js

24 lines
588 B
JavaScript
Raw Normal View History

2019-03-15 14:53:48 +00:00
// audio for events
// AUDIO SETUP
const audioEngine = new (window.AudioContext || window.webkitAudioContext)()
audioEngine.suspend()
const masterGain = audioEngine.createGain()
const audioEl = document.querySelector('#audioToggle')
2019-03-15 14:53:48 +00:00
masterGain.gain.value = 0.9
masterGain.connect(audioEngine.destination)
// window.onload = function() {
// // create gain
// }
2019-03-15 14:53:48 +00:00
const audioToggle = () => {
audioEl.classList.toggle('active');
if (audioEngine.state == 'suspended') {
audioEngine.resume()
} else {
audioEngine.suspend()
}
}
2019-03-15 14:53:48 +00:00
audioEl.addEventListener('click', audioToggle)