简体   繁体   中英

Playing a video using HTML5/JQuery

My HTML5 video code:

<video id="myVideo">
<source src="Some source" type="some type" \>
</video>

My play button click function:

$("#myVideo").play();

The code is not working for me. I checked the code with default browser controls for video - Its working fine. The only problem is when i try to make a custom control play button.

Try using $('#myVideo').get(0).play(); instead.

Not that you even need to use jQuery to do so:

document.getElementById('myVideo').play();

you can just use HTML either via autoplay or after a button is clicked using the .click() method. as the user above mentioned, you can use #myVideo which can also give you the ability to format and position the video in css.. as shown below:

#myVideo {
margin-left: auto;
margin-right: auto;
top : auto;
display: block;
width: 50%;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM