javascript - IOS WeChat audio tag cannot be played through touchend
给我你的怀抱
给我你的怀抱 2017-06-30 09:56:15
0
2
926

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

给我你的怀抱
给我你的怀抱

reply all(2)
Peter_Zhu

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;

ringa_lee

This method is the solution!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!