Use Javascript to Play HTML5 Video [closed]

二次信任 提交于 2020-01-03 13:07:34

问题


How can I use Javascript to play an HTML5 video?

For example, play the video at an onclick event.


回答1:


<video id = 'video'>
<!-- Your video's source -->
</video>
<button id='playVid'>Play</button>

<script>
document.getElementById('playVid').onclick = function (){
    document.getElementById('video').play();
};
</script>

Add an event listener to your 'Play' button where it calls videoElem.play(), like I've done above.



来源:https://stackoverflow.com/questions/12201488/use-javascript-to-play-html5-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!