问题
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