在touchstart後播放某些音頻時出現問題。我有以下的代碼,我在Chrome 57上運行這樣做:在touchstart上播放音頻
<!DOCTYPE html>
<html>
\t <head>
\t \t <meta charset="utf-8">
\t \t <title>Play Media on user touch</title>
\t </head>
\t <body>
\t \t <div id="play">Click me to play audio!</div>
\t \t <script type="text/javascript">
\t \t \t document.querySelector('#play').addEventListener('touchstart', function() {
new Audio('http://techslides.com/demos/samples/sample.mp3').play() \t \t \t \t
\t \t \t })
\t \t </script>
\t </body>
</html>
當我打開這個我的移動設備和測試touchstart,我在控制檯收到此錯誤:
Warning: Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture.
Error: Uncaught (in promise) DOMException: play() can only be initiated by a user gesture.
touchstart是否被視爲用戶手勢?這是故意的行爲還是錯誤?