commit f7bb22501f93754ad15c6bb1c49482b6b85a1eea parent 8bd562f091b3f32ed17b283b8a835ae5dc1659e6 Author: Yuval Langer <yuval.langer@gmail.com> Date: Sat, 12 Mar 2022 01:26:37 +0200 Define Audio nodes in HTML and clone those for concurrent playing. Also add a timeout for the scream. Diffstat:
M | html/wtc_plaza_2001-09-11/index.html | | | 2 | ++ |
M | html/wtc_plaza_2001-09-11/wtc_plaza_2001-09-11.js | | | 10 | +++++----- |
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/html/wtc_plaza_2001-09-11/index.html b/html/wtc_plaza_2001-09-11/index.html @@ -8,6 +8,8 @@ <body> WTC Plaza circa 2001-09-11: <canvas id="canvas" width="500" height="500"></canvas> + <audio id="scream_audio" src="freesound.org/data/previews/239/239900_4079949-lq.mp3"></audio> + <audio id="thump_audio" src="freesound.org/data/previews/344/344150_6179115-lq.mp3"></audio> <button id="jump_button">Jump</button> <button id="clear_button">Clear</button> <hr> diff --git a/html/wtc_plaza_2001-09-11/wtc_plaza_2001-09-11.js b/html/wtc_plaza_2001-09-11/wtc_plaza_2001-09-11.js @@ -195,19 +195,19 @@ Math.TAU = 2 * Math.PI; } function jump() { - let scream_audio_element = new Audio("freesound.org/data/previews/239/239900_4079949-lq.mp3"); + let scream_audio_element = document.getElementById('scream_audio').cloneNode(true); scream_audio_element.play(); - scream_audio_element.addEventListener('ended', function() { - let thump = new Audio("freesound.org/data/previews/344/344150_6179115-lq.mp3"); + setTimeout(function() { + scream_audio_element.pause(); + let thump = document.getElementById('thump_audio').cloneNode(true); thump.currentTime = 0.2; - thump.play(); draw_jumper(); - }); + }, 1700); } function clear_canvas() {