To make an h5 mini-game, you need to long press and release the button to play a sound effect
GameStart.addEventListener('touchend', function(event) {
event.preventDefault();
Audio.play();
}, false);
The mechanism of IOS must be manually triggered by the user, but this should be considered correct for me, right?
I don’t understand very much, but it can be played normally with touchstart. I hope someone can explain it,
or something else The solution can solve my need.
Long press the button and release it before playing the sound effect
Note: On iOS, the Web Audio API requires sounds to be triggered from an explicit user action, such as a tap. Calling noteOn() from an onload event will not play sound.
I searched for a long time but couldn’t find Apple’s exact definition of user action. Maybe touchend does not belong to user action
As far as I can try now, click and touchstart are feasible
You can try to execute Audio.load() at touchstart, and then execute Audio.play() at touchend;
This method is the solution!