Preloading sound problem

Hello,

I have some problems with cocos sound engine.
What I do:
I put audio path to g_resources object and preloaded audio with

LoaderScene.preload(g_resources, callback, context)

And then I tried play it with

cc.audioEngine.playEffect(soundName, loop);

Sound played correctly, but with some delay. It seems like sound was loaded again, and then have played:

I’m working with cocos2d-JS v3.13 develop branch
Would you be so kind to help me please…

Try to load the sound effects like this:

//Load Sounds Effects
    var engine = cc.AudioEngine.getInstance();
    engine.preloadEffect(soundName);

it worked for me, but I think you can’t preload Background Music.

1 Like

thanks for your reply
please tell me, which cocos2d version are you use?
Unfortunately I haven’t “preloadEffect” method in my cc.audioEngine (cocos2d-JS v3.13)
I’m looking into CCAudio.js and haven’t find it…

I found preloadEffect in CCComAudio.js, but I don’t know how to use it…

Problem is solved by adding preloadEffect method into CCAudio.js

preloadEffect: function (url) {
	var self = this;
	loader.useWebAudio = true;
	cc.loader.load(url, function (audio) {
		audio = cc.loader.getRes(url);
		audio = audio.cloneNode();
		if (!self._audioPool[url])
			self._audioPool[url] = [];
		self._audioPool[url].push(audio);
	});
	loader.useWebAudio = false;
}

It works. If it will be useful for somebody else - I can create pull request. Just let me know. Original branch is here.

1 Like

It works! It’s useful for me! Thanks a lot!