cocos2d-html5
cocos2d-html5 copied to clipboard
cc.audioEngine.playEffect returning null but is playing anyways
Hi , i just found out that if the audio (mp3 in my case) is playing using cc.audioEngine.playEffect when the loading hasn't finished, the sound will play but retuning null as an audio id, the problem is when the sound is playing in a loop, amd there no sound id to stop it. any thouhgt?? cheers
The very easy way to fix this problem, if you check audioId is null or underfined please call cc.audioEngine.stopAllEffects(); -- declare
slot.SoundManager = cc.Class.extend({
ctor: function () {
},
soundEffect: function (url, loop) {
var audioId = cc.audioEngine.playEffect(url, loop);
return audioId;
},
stopAllEffect: function () {
cc.audioEngine.stopAllEffects();
},
stopEffectByID: function (id) {
cc.audioEngine.stopEffect(id);
}
});
--- in use
if (this.audioId) {
this.soundManager.stopEffectByID(this.audioId);
} else {
this.soundManager.stopAllEffect();
}