首页 >社区问答列表 >javascript - IOS微信audio标签不能通过touchend播放

javascript - IOS微信audio标签不能通过touchend播放

做个h5小游戏,需要长按按钮放开后播放一个音效

GameStart.addEventListener('touchend', function(event) {
    event.preventDefault();
    Audio.play();
}, false);

IOS的机制是必须通过用户手动触发, 可是我这应该也算才对吧?
很是不明白,用touchstart则可以正常播放,希望大神能讲解下,
或者有什么方案可以解决我这个需求,
长按按钮放开后再播放音效

  • 天蓬老师
  • 天蓬老师    2017-06-30 09:58:152楼

    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.

    我搜了半天也没找到苹果关于user action的确切定义,可能touchend不属于user action
    就目前尝试,click与touchstart是可行的

    你可以尝试在touchstart时执行Audio.load(),在touchend是再执行Audio.play();

    +0添加回复

  • 回复