phaserjs/phaser · error · Error
Audio key "
Error message
Audio key "
What it means
Thrown by WebAudioSound constructor when manager.game.cache.audio.get(key) returns a falsy value. Identical cause to the HTML5 path but for the WebAudio backend: the decoded AudioBuffer must be present in the audio cache before a WebAudioSound can wrap it.
Source
Thrown at src/sound/webaudio/WebAudioSound.js:58
initialize:
function WebAudioSound (manager, key, config)
{
if (config === undefined) { config = {}; }
/**
* Audio buffer containing decoded data of the audio asset to be played.
*
* @name Phaser.Sound.WebAudioSound#audioBuffer
* @type {AudioBuffer}
* @since 3.0.0
*/
this.audioBuffer = manager.game.cache.audio.get(key);
if (!this.audioBuffer)
{
throw new Error('Audio key "' + key + '" not found in cache');
}
/**
* A reference to an audio source node used for playing back audio from
* audio data stored in Phaser.Sound.WebAudioSound#audioBuffer.
*
* @name Phaser.Sound.WebAudioSound#source
* @type {?AudioBufferSourceNode}
* @default null
* @since 3.0.0
*/
this.source = null;
/**
* A reference to a second audio source used for gapless looped playback.
*
* @name Phaser.Sound.WebAudioSound#loopSource
* @type {?AudioBufferSourceNode}View on GitHub (pinned to 41be1e462b)
Solutions
- Preload with this.load.audio(key, url) using the exact key.
- Defer sound.add to create() or a loader.on('complete') callback.
- Guard with this.game.cache.audio.has(key).
- Confirm the file is a browser-supported codec and loads without 404.
Example fix
// before
this.sound.add('music'); // not loaded
// after
preload() { this.load.audio('music', 'audio/music.ogg'); }
create() { this.sound.add('music'); } Defensive patterns
Strategy: validation
Validate before calling
function addWebAudioSound(manager, key) {
if (!manager.game.cache.audio.has(key)) {
throw new Error(`Audio '${key}' not in cache; call this.load.audio first`);
}
return new Phaser.Sound.WebAudioSound(manager, key);
} Type guard
function audioCached(game, key) { return game.cache.audio.has(key); } Prevention
- Preload with this.load.audio.
- Wait for loader completion before sound.add.
- Verify file format and HTTP status.
When it happens
Trigger: Constructing new Phaser.Sound.WebAudioSound(manager, key) for an unloaded key; misspelled key; loader not yet complete; audio decode failed so the buffer is missing from cache.
Common situations: Forgetting the load.audio call; calling from preload instead of create; failed/aborted decode (corrupt file, unsupported codec); key mismatch between load and add; audio type mismatch (e.g. loading as text).
Related errors
- No cached audio asset with key "
- Invalid File type:
- Invalid File key:
- URL Error in File:
- BaseFilterShader: No fragment shader source provided and no
AI-assisted analysis of phaserjs/phaser@41be1e462b (2026-08-13).
Data as JSON: /api/errors/f22cb6ea9328ed3b.
Report an issue: GitHub.