Create AudioContext only when needed
This commit is contained in:
@@ -11,7 +11,7 @@ export type SoundOpts = {
|
||||
export class Sound {
|
||||
static sounds = new Map();
|
||||
|
||||
private readonly context = new AudioContext();
|
||||
private static context: AudioContext | undefined;
|
||||
|
||||
private readonly loop: boolean;
|
||||
|
||||
@@ -59,6 +59,13 @@ export class Sound {
|
||||
}
|
||||
}
|
||||
|
||||
private get context(): AudioContext {
|
||||
if (!Sound.context) {
|
||||
Sound.context = new AudioContext();
|
||||
}
|
||||
return Sound.context;
|
||||
}
|
||||
|
||||
static async loadSoundFile(src: string): Promise<ArrayBuffer> {
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
|
Reference in New Issue
Block a user