I’m trying to play my audios with DOM Audio instead of WebAudio (Which is the default mode). However, when I try to play a AudioClip with download mode set as DOM Audio I get the following error:
CCAudio.js:290 Uncaught TypeError: Failed to set the 'buffer' property on 'AudioBufferSourceNode': The provided value is not of type 'AudioBuffer'.
at WebAudioElement.proto.play (CCAudio.js:290)
at Audio.proto.play (CCAudio.js:146)
at Audio.<anonymous> (CCAudioSource.js:257)
at Audio.cb (event-target.js:308)
at EventListeners.invoke (event-listeners.js:49)
at Audio.emit (event-target.js:360)
at Audio.proto.preload (CCAudio.js:107)
at cc_AudioSource.play (CCAudioSource.js:259)
I’m currently using Cocos Creator version 1.4.2
EDIT 1:
After further testing, I’ve noticed that this error only happens if I’m trying to play an AudioClip from a prefab that wasn’t preloaded.
You can replicate this by doing the following steps:
1 - Create a prefab with an AudioSource and reference a AudioClip that is not referenced by any asset on the scene
2 - Load the prefab using cc.loader.loadRes.
3 - Instantiate the prefab using cc.instantiate.
4 - Play the AudioSource.
You should be able to replicate this using the following code:
cc.loader.loadRes('myPrefab', cc.Prefab, function (err, result) {
if (err) {
cc.log(err);
} else {
var obj = cc.instantiate(result);
obj.parent = cc.director.getScene();
obj.getComponent(cc.AudioSource).play();
}
});