移动端触摸按钮视频开始播放

有一个需求是长按按钮视频开始自动播放,刚开始发现一直会报play() failed because the user didn't interact with the document first,找到问题说是chrome为了避免标签产生随机噪音,给video加个muted静音就可以了,但是不想静音有什么解决方法

相关代码

// <video id="video1" width="320" height="240" controls muted>

    <source src="1.mp4" type="video/mp4">
</video>
<button class="button1">特效1</button>

<script>
window.onload = function () {
    var myVid=document.getElementById("video1");
    var box = document.querySelector('.button1');
    box.addEventListener('touchstart',function (e) {
        // console.log('start');
        myVid.play();
        myVid.muted = false
    });
    box.addEventListener('touchmove',function (e) {
        console.log('move');
        console.log(e);
    });
    box.addEventListener('touchend',function (e) {
        console.log('end');
        console.log(e);
        myVid.pause();
    });
}
</script>

阅读 2.1k
1 个回答

有没有大神来指点下

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题