1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-22 14:33:51 +00:00

audio: clear buffers when stopping in case browser keeps playing anyway

This commit is contained in:
Steven Hugg 2019-08-27 21:04:52 -04:00
parent ceea8f292b
commit 4a49df6f3e
2 changed files with 7 additions and 2 deletions

View File

@ -178,7 +178,6 @@ TODO:
- can't step back twice?
- compiler bug in chase
- "shared" in URL doesn't work, leave in URL? (also importURL)
- alert when skeleton file loaded or file not found
- TypeError: null is not an object (evaluating 'n.destination')
https://8bitworkshop.com/v3.4.1/javatari.js/release/javatari/javatari.js

View File

@ -384,6 +384,12 @@ export var SampleAudio = function(clockfreq) {
}
}
function clearBuffers() {
if (bufferlist)
for (var buf of bufferlist)
buf.fill(0);
}
function createContext() {
var AudioContext = window['AudioContext'] || window['webkitAudioContext'] || window['mozAudioContext'];
if (! AudioContext) {
@ -425,7 +431,6 @@ export var SampleAudio = function(clockfreq) {
// Chrome autoplay (https://goo.gl/7K7WLu)
if (this.context.state == 'suspended') {
this.context.resume();
console.log('AudioContext should resume');
}
return; // already created
}
@ -447,6 +452,7 @@ export var SampleAudio = function(clockfreq) {
this.stop = function() {
this.context && this.context.suspend();
clearBuffers(); // just in case it doesn't stop immediately
}
this.close = function() {