search

Home  >  Q&A  >  body text

javascript - IOS WeChat audio tag cannot be played through touchend

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

给我你的怀抱给我你的怀抱2784 days ago1006

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-06-30 09:58:15

    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;

    reply
    0
  • ringa_lee

    ringa_lee2017-06-30 09:58:15

    This method is the solution!

    reply
    0
  • Cancelreply