您的位置:首頁技術文章
文章詳情頁

javascript - IOS微信audio標簽不能通過touchend播放

瀏覽:145日期:2022-06-24 14:37:41

問題描述

做個h5小游戲,需要長按按鈕放開后播放一個音效

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

IOS的機制是必須通過用戶手動觸發, 可是我這應該也算才對吧?很是不明白,用touchstart則可以正常播放,希望大神能講解下,或者有什么方案可以解決我這個需求,長按按鈕放開后再播放音效

問題解答

回答1:

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();

回答2:

這個方法喲,解決了!

標簽: 微信
相關文章:
国产综合久久一区二区三区