Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- // TODO Group audio files so we can control volume seperately
- const context = new AudioContext();
- const soundDatas = {};
- const soundFiles = {
- clear: '/audio/clear.wav',
- fall: '/audio/fall.wav',
- land: '/audio/land.wav',
- lock: '/audio/lock.wav',
- irs: '/audio/irs.wav',
- };
- for (let key in soundFiles) {
- const request = new Request(soundFiles[key]);
- fetch(request).then(body => {
- return body.arrayBuffer();
- }).then(buffer => {
- context.decodeAudioData(buffer, data => {
- soundDatas[key] = data;
- });
- });
- }
- function play(key) {
- // TODO Check if loaded.
- const source = context.createBufferSource();
- source.buffer = soundDatas[key];
- source.connect(context.destination);
- source.start(0);
- }
- // e.g.,
- // play('fall');
- // TODO Promise.all for onload
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement