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

Effect Sound auto plays old paths

Open letrungtrung opened this issue 9 years ago • 6 comments

On Web, i play game and then i change to other tab and final back to game tab. The effect sound bug occurs, it plays old paths again. This bug just had in version 3.3 and 3.5.

letrungtrung avatar Apr 04 '15 02:04 letrungtrung

I have the same problem.

IgorMats avatar May 07 '15 15:05 IgorMats

Please try v3.6, @VisualSJ should have fixed the issue

pandamicro avatar May 08 '15 02:05 pandamicro

Hi @pandamicro , the problem still occurs in v3.6

letrungtrung avatar May 15 '15 14:05 letrungtrung

@letrungtrung What browser appeared this problem? what is the browser version?

I use firefox 36, Didn't recreate the problem... I will continue to try it. Thanks ^.^

VisualSJ avatar May 20 '15 06:05 VisualSJ

hi @VisualSJ I'm testing on firefox v38.0.1 and chrome v42.0.2311.152 . Both browsers occurred that problem.

letrungtrung avatar May 20 '15 07:05 letrungtrung

After doing some checking I discovered the reason that caused the error is in _resumeOfWebAudio (CCAudio.js). And this is my solution:

  _resumeOfWebAudio: function () {
        var audio = this._currentSource;
        if (audio) {
            this._startTime = this._context.currentTime;

            // === Start my code
            var numOfPlayed = Math.floor(this._currentTime / audio.buffer.duration);
            if ((this.loop && numOfPlayed >= this.loop) || (!this.loop && numOfPlayed !== 0)) {
                this._stopOfWebAudio();
                return;
            }
            if (this.loop)
                this.loop -= numOfPlayed;
           //=== End my code

            var offset = this._currentTime % audio.buffer.duration;
            this._playOfWebAudio(offset);
        }
    }

This is only a temporary solution while waiting for the official fixing!

letrungtrung avatar Jul 20 '15 08:07 letrungtrung