MCPcopy Create free account
hub / github.com/Monogatari/Monogatari / createAudioPlayer

Method createAudioPlayer

src/actions/Play.ts:242–268  ·  view source on GitHub ↗
(paused = false, volume = 1)

Source from the content-addressed store, hash-verified

240 }
241
242 async createAudioPlayer(paused = false, volume = 1): Promise<any> {
243 const audioContext = this.engine.audioContext!;
244 const gainNode = audioContext.createGain();
245 gainNode.connect(audioContext.destination);
246
247 // Check if audio is already cached
248 const cacheKey = `${this.directory}/${this.mediaKey}`;
249 let audioBuffer = this.engine.audioBufferCache(cacheKey);
250
251 if (!audioBuffer) {
252 // Load and decode audio file
253 const assetsPath = this.engine.setting('AssetsPath') as Record<string, string>;
254 const response = await fetch(`${assetsPath.root}/${assetsPath[this.directory]}/${this.media}`);
255 const arrayBuffer = await response.arrayBuffer();
256 audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
257 }
258
259 // Parse effects from props
260 const effects = this.parseEffects();
261
262 return new AudioPlayer(audioContext, audioBuffer, {
263 outputNode: gainNode,
264 effects: effects,
265 paused: paused,
266 volume: volume
267 });
268 }
269
270 parseEffects(): Record<string, any> {
271 const availableEffects = AudioPlayer.effects();

Callers 1

applyMethod · 0.95

Calls 3

parseEffectsMethod · 0.95
audioBufferCacheMethod · 0.80
settingMethod · 0.80

Tested by

no test coverage detected