Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions fetch/fetch-array-buffer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h1>Fetch arrayBuffer example</h1>
const play = document.querySelector(".play");
const stop = document.querySelector(".stop");
const errorDisplay = document.querySelector(".error");
let currentSource = null;

// use fetch to load an audio track, and
// decodeAudioData to decode it and stick it in a buffer.
Expand Down Expand Up @@ -53,7 +54,8 @@ <h1>Fetch arrayBuffer example</h1>
getData()
.then((source) => {
errorDisplay.innerHTML = "";
source.start(0);
currentSource = source;
currentSource.start(0);
play.disabled = true;
})
.catch((error) => {
Expand All @@ -64,8 +66,10 @@ <h1>Fetch arrayBuffer example</h1>
};

stop.onclick = () => {
source.stop(0);
play.disabled = false;
if (currentSource){
currentSource.stop(0);
play.disabled = false;
}
};

// dump script to pre element
Expand Down