mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-31 23:29:27 +08:00
继续bgm的播放
This commit is contained in:
parent
5aed6393a2
commit
48a0752f9c
@ -3,6 +3,7 @@ import { ResourceController } from '../loader/controller';
|
|||||||
|
|
||||||
export class BgmController extends ResourceController<HTMLAudioElement> {
|
export class BgmController extends ResourceController<HTMLAudioElement> {
|
||||||
playing?: BgmIds;
|
playing?: BgmIds;
|
||||||
|
lastBgm?: BgmIds;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个bgm
|
* 添加一个bgm
|
||||||
@ -23,11 +24,12 @@ export class BgmController extends ResourceController<HTMLAudioElement> {
|
|||||||
*/
|
*/
|
||||||
play(id: BgmIds, when: number = 0) {
|
play(id: BgmIds, when: number = 0) {
|
||||||
if (this.playing === id) return;
|
if (this.playing === id) return;
|
||||||
this.stop();
|
this.pause();
|
||||||
const bgm = this.get(id);
|
const bgm = this.get(id);
|
||||||
bgm.currentTime = when;
|
bgm.currentTime = when;
|
||||||
bgm.play();
|
bgm.play();
|
||||||
this.playing = id;
|
this.playing = id;
|
||||||
|
this.lastBgm = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,10 +44,20 @@ export class BgmController extends ResourceController<HTMLAudioElement> {
|
|||||||
/**
|
/**
|
||||||
* 停止当前的bgm播放
|
* 停止当前的bgm播放
|
||||||
*/
|
*/
|
||||||
stop() {
|
pause() {
|
||||||
if (!has(this.playing)) return;
|
if (!has(this.playing)) return;
|
||||||
const bgm = this.get(this.playing);
|
const bgm = this.get(this.playing);
|
||||||
bgm.pause();
|
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) {
|
get(id: BgmIds) {
|
||||||
|
Loading…
Reference in New Issue
Block a user