在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是否被视为用户手势?这是故意的行为还是错误?