I have multiple videos on a page.
<div class="row text-center">
<video width="320" height="240" controls class="myvideo">
<source src="http://www.html5videoplayer.net/videos/toystory.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
<div class="row text-center">
<video width="320" height="240" controls class="myvideo">
<source src="http://www.html5videoplayer.net/videos/fantasy.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
I want to add buffering events to them. Also, when I click video 1, video 2 (if playing) should automatically stop. How can I achieve this? They have a common class. Shall I have to implement ids with them?
give Ids to your videos:
<video width="320" height="240" controls class="myvideo" id="myVideoOne">
<video width="320" height="240" controls class="myvideo" id="myVideoTwo">
for buffering :
var vid = document.getElementById("myVideoOne");
alert("Start: " + vid.buffered.start(0)
+ " End: " + vid.buffered.end(0));
var vid = document.getElementById("myVideoTwo");
alert("Start: " + vid.buffered.start(0)
+ " End: " + vid.buffered.end(0));
for stoping automatically you can use this inside your videoPlay1 and videoPlay2 functions:
function videoPlay1() {
var video1 = document.getElementById("myVideoOne");
var video2 = document.getElementById("myVideotwo");
if (video1.paused) {
video1.play();
video2.pause();
} else {
video1.pause();
video2.pause();
}
}
function videoPlay2() {
var video1 = document.getElementById("myVideoOne");
var video2 = document.getElementById("myVideotwo");
if (video2.paused) {
video2.play();
video1.pause();
} else {
video1.pause();
video2.pause();
}
}
example : to set a loader for myVideoOne you can use this jquery: css:
video.loading {
background: black url(/yourGifImg.gif) center center no-repeat;
}
jquery:
$('#myVideoOne').on('loadstart', function (event) {
$(this).addClass('loading')
});
$('#myVideoOne').on('canplay', function (event) {
$(this).removeClass('loading')
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With