heaventaker/src/stores/music.js
2021-08-25 20:43:25 +02:00

44 lines
No EOL
908 B
JavaScript

import { Howl } from "howler";
export const musicStore = {
departure: {
src: "mittsies-departure.mp3",
bpm: 128,
scale: 1/2,
/** @type {Howl} */
howl: null
}
}
export class Music {
static current = musicStore.departure;
/**
* @param {keyof musicStore} key
*/
static play(key) {
this.current.howl.pause();
this.current = musicStore[key];
if(!this.current.howl) this.prepare();
this.current.howl.play();
}
static prepare() {
this.current.howl = new Howl({
src: "./sound/" + this.current.src,
html5: true,
loop: true
});
}
static startPlaying() {
if(!this.current.howl.playing())
this.current.howl.play();
}
}
Music.prepare();
Music.startPlaying();
export function startPlaying(e) {
Music.startPlaying();
}