cocos2d-html5 icon indicating copy to clipboard operation
cocos2d-html5 copied to clipboard

cc.audioEngine.playEffect returning null but is playing anyways

Open milomartinez opened this issue 7 years ago • 1 comments

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

milomartinez avatar Jun 12 '18 21:06 milomartinez

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();
       }

hoanghiep271295 avatar Dec 12 '19 10:12 hoanghiep271295