Browse Source

Added a basic demo of sound

tags/v0.1.0
Fen Dweller 6 years ago
parent
commit
7e144db282
No known key found for this signature in database GPG Key ID: E80B35A6F11C3656
3 changed files with 25 additions and 15 deletions
  1. +5
    -3
      audio.js
  2. +4
    -10
      satiate.html
  3. +16
    -2
      satiate.js

+ 5
- 3
audio.js View File

@@ -1,5 +1,7 @@
let playing = []; let playing = [];
looping = {};
let looping = {};

const audioBaseUrl = "http://localhost:8000/media/audio/";


let audioDict = {}; let audioDict = {};


@@ -111,9 +113,9 @@ function loadRemoteAudio(name) {


xhr.open("GET", audioBaseUrl + name, true); xhr.open("GET", audioBaseUrl + name, true);
xhr.responseType = "arraybuffer"; xhr.responseType = "arraybuffer";
xhr.onload = (xhr) => {
xhr.onload = (res) => {
if (xhr.status == 200) if (xhr.status == 200)
cacheAndParse(name, xhr.data);
cacheAndParse(name, xhr.response);
else else
console.log("Couldn't load " + name); console.log("Couldn't load " + name);
} }


+ 4
- 10
satiate.html View File

@@ -34,16 +34,10 @@
</div> </div>
<div id="control-area"> <div id="control-area">
<div id="actions"> <div id="actions">
<button class="action-button">potato 1</button>
<button class="action-button">potato 2</button>
<button class="action-button">potato 3</button>
<button class="action-button">potato 4</button>
<button class="action-button">potato 5</button>
<button class="action-button">potato 6</button>
<button class="action-button">potato 7</button>
<button class="action-button">potato 8</button>
<button class="action-button">potato 9</button>
<button class="action-button">potato 10</button>
<button class="action-button" id="load">Load Sounds</button>
<button class="action-button" id="sfx">Play Sound</button>
<button class="action-button" id="loop">Play Loop</button>
<button class="action-button" id="stop">Stop Loop</button>
</div> </div>
<div id="desc"> <div id="desc">
this is a description of your action this is a description of your action


+ 16
- 2
satiate.js View File

@@ -1,7 +1,5 @@
"use strict" "use strict"


let audioBaseUrl = "http://localhost:8000/media/audio/";

let audioContext; let audioContext;


// setup the game // setup the game
@@ -9,6 +7,22 @@ let audioContext;
function init() { function init() {
initAudio(); initAudio();


document.querySelector("#load").addEventListener("click", () => {
loadAudio("sfx/test.ogg");
loadAudio("loop/test.ogg");
});

document.querySelector("#sfx").addEventListener("click", () => {
playSfx("sfx/test.ogg");
});

document.querySelector("#loop").addEventListener("click", () => {
playLoop("loop/test.ogg");
});

document.querySelector("#stop").addEventListener("click", () => {
stopLoop("loop/test.ogg");
});


} }




Loading…
Cancel
Save