Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Javascript to Play HTML5 Video [closed]

How can I use Javascript to play an HTML5 <video>?

For example, play the video at a onclick event.

like image 544
David Avatar asked Aug 30 '12 16:08

David


1 Answers

Add an event listener to your play button where it calls videoElem.play()

HTML:

<video id='video'>
    <source src="your-video-source.mp4" type="video/mp4">
</video>

<button id='playVid'>Play</button>

Javascript:

document.getElementById('playVid').onclick = function () {
    document.getElementById('video').play();
};
like image 100
Some Guy Avatar answered Oct 08 '22 07:10

Some Guy