继续bgm的播放

This commit is contained in:
unanmed 2023-06-21 17:13:38 +08:00
parent 5aed6393a2
commit 48a0752f9c

View File

@ -3,6 +3,7 @@ import { ResourceController } from '../loader/controller';
export class BgmController extends ResourceController<HTMLAudioElement> {
playing?: BgmIds;
lastBgm?: BgmIds;
/**
* bgm
@ -23,11 +24,12 @@ export class BgmController extends ResourceController<HTMLAudioElement> {
*/
play(id: BgmIds, when: number = 0) {
if (this.playing === id) return;
this.stop();
this.pause();
const bgm = this.get(id);
bgm.currentTime = when;
bgm.play();
this.playing = id;
this.lastBgm = id;
}
/**
@ -42,10 +44,20 @@ export class BgmController extends ResourceController<HTMLAudioElement> {
/**
* bgm播放
*/
stop() {
pause() {
if (!has(this.playing)) return;
const bgm = this.get(this.playing);
bgm.pause();
delete this.playing;
}
/**
* BGM的播放
*/
resume() {
if (has(this.playing) || !this.lastBgm) return;
const bgm = this.get(this.lastBgm);
bgm.play();
}
get(id: BgmIds) {