mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-25 18:54:30 +08:00
资源加载,bgm和音效播放
This commit is contained in:
1 parent
6f59ea51ac
commit
5aed6393a2
16 files changed
+289
-52
No files matched your search
@@ -44,6 +44,7 @@ export class AudioPlayer extends EventEmitter<AudioPlayerEvent> {
|
||||
async update(data: ArrayBuffer) {
|
||||
this.data = data;
|
||||
this.buffer = await ac.decodeAudioData(data);
|
||||
|
||||
this.emit('update', this.buffer);
|
||||
}
|
||||
|
||||
@@ -61,9 +62,10 @@ export class AudioPlayer extends EventEmitter<AudioPlayerEvent> {
|
||||
* 播放音频
|
||||
*/
|
||||
play(when?: number, offset?: number, duration?: number) {
|
||||
if (!this.source) return;
|
||||
this.ready();
|
||||
this.source?.start(when, offset, duration);
|
||||
if (!this.source) return;
|
||||
|
||||
this.source.start(when, offset, duration);
|
||||
|
||||
const source = this.source;
|
||||
this.source?.addEventListener('ended', ev => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { has } from '../../plugin/utils';
|
||||
import { ResourceController } from '../loader/controller';
|
||||
|
||||
class BgmController extends ResourceController<HTMLAudioElement> {
|
||||
export class BgmController extends ResourceController<HTMLAudioElement> {
|
||||
playing?: BgmIds;
|
||||
|
||||
/**
|
||||
@@ -27,6 +27,7 @@ class BgmController extends ResourceController<HTMLAudioElement> {
|
||||
const bgm = this.get(id);
|
||||
bgm.currentTime = when;
|
||||
bgm.play();
|
||||
this.playing = id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,13 +49,6 @@ class BgmController extends ResourceController<HTMLAudioElement> {
|
||||
}
|
||||
|
||||
get(id: BgmIds) {
|
||||
return this.list[`bgm.${id}`];
|
||||
return this.list[`bgms.${id}`];
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface AncTe {
|
||||
bgm: BgmController;
|
||||
}
|
||||
}
|
||||
ancTe.bgm = new BgmController();
|
||||
@@ -132,7 +132,10 @@ export class SoundEffect extends AudioPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
class SoundController extends ResourceController<ArrayBuffer, SoundEffect> {
|
||||
export class SoundController extends ResourceController<
|
||||
ArrayBuffer,
|
||||
SoundEffect
|
||||
> {
|
||||
private seIndex: Record<number, SoundEffect> = {};
|
||||
|
||||
/**
|
||||
@@ -196,10 +199,3 @@ class SoundController extends ResourceController<ArrayBuffer, SoundEffect> {
|
||||
return this.list[`sounds.${sound}`];
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface AncTe {
|
||||
sound: SoundController;
|
||||
}
|
||||
}
|
||||
ancTe.sound = new SoundController();
|
||||
Reference in new issue
Block a user