CC3.1.1 Bug Audio plays double on first time

Hello

My project targets web

The following situation is happening: Even if the player touch or clicks in the game frame the first button that he interacts to does not play the audio and then the second button plays the audio two times.

After that the audio plays nicely. It’s just the first audio.

I tried creating a “Click to start” screen before any audio is needed to force the player to interact with the game, but even with that I’m still experiencing this first button no audio plays and second button plays audio twice.

Is this a Cocos bug or is this something about the browser?

Thanks

did you register the touch event with Node.EventType.TouchEnd ?
please try Node.EventType.TouchStart

I’m using Button.EventType.CLICK, just tried Node.EventType.TouchStart and had the same problem

Hello, here is a video demonstrating the problem

The top button just play the audio in this simple way for testing:
image

The second button goes through a custom audio manager with key->clip, but the hook is like this:

UIClickSFX.ts

    onLoad() {        
        this.node.on(Button.EventType.CLICK, this.onclick, this);
    }

    onclick() {
        if (this.key)
            AudioManager.instance?.playByKey(this.key);
    }

In AudioManager.ts the playByKey just finds the clip and at the end call this:

    public playOneShot(clip: AudioClip, volumeScale = 1) {
        if (!this.isAudioEnabled)
            return;
        if (!clip)
            return;
        if (this.source)
            this.source.playOneShot(clip, volumeScale);
        else
            logger.log(`ERROR: AudioSource is null`);
    }

Hope that these extra info help

Sorry for late reply,
This issue is fixed on 3.4.0

The pull request to fix this issue

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.