38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
// @license magnet:?xt=urn:btih:90dc5c0be029de84e523b9b3922520e79e0e6f08&dn=cc0.txt CC0-1.0
|
|
/****************************************************************************
|
|
* BPS (Bill Paxton Soundboard)
|
|
*
|
|
* Copyright 2024 Eric Woodward
|
|
* Source released under CC0 Public Domain License v1.0
|
|
* https://www.itsericwoodward.com/licenses/cc0/
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
****************************************************************************/
|
|
|
|
// adapted from https://cheatcode.co/tutorials/how-to-build-a-soundboard-with-javascript
|
|
|
|
let sounds = [];
|
|
|
|
const injectPlayerIntoPage = (name, path) => {
|
|
const player = document.createElement("audio");
|
|
player.id = name;
|
|
player.src = path;
|
|
player.volume = 0.5;
|
|
player.type = "audio/mpeg";
|
|
document.body.appendChild(player);
|
|
},
|
|
load = (name, path) => {
|
|
sounds = [...sounds, { name, path }];
|
|
injectPlayerIntoPage(name, path);
|
|
},
|
|
play = (name) => {
|
|
const player = document.getElementById(name);
|
|
if (player) {
|
|
player.pause();
|
|
player.currentTime = 0;
|
|
player.play();
|
|
}
|
|
};
|
|
|
|
export { load, play };
|
|
// @license-end
|