Add this JS code:
const vid = document.querySelector('#primorvid');
let currentTime = 0;
vid.addEventListener('click', function(e) {
if (vid.paused) {
currentTime = vid.currentTime;
vid.load();
} else {
vid.currentTime = currentTime;
}
});
Explanation:
const vid = document.querySelector('#primorvid');
let currentTime = 0;
Just getting the video and storing it in vid
, and declaring a currentTime
where we will store the time at which the video was paused.
We add a click event listener to the video:
vid.addEventListener('click', function(e) { ... });
If the video's last state was playing (i.e. it is now paused), save the current time and reload it (this shows the poster and pauses the video):
if (vid.paused) {
currentTime = vid.currentTime;
vid.load();
} else {
vid.currentTime = currentTime;
}
Else, set the current time to what it was before and play again.
Another solution which wouldn't imply buffering the video again would be to set an overlaying element with your poster and show it when the video is paused, alongside an event listener.
You can try this.
var vrVid = document.getElementById("primorvid");
var pauseTime = vrVid.currentTime;
vrVid.load();
vrVid.currentTime = pauseTime;
vrVid.play();
I think it will solve your issue but i don't think it's best solution because it will reload the video and it will buffer.
Post a Comment for "Show The Poster After Pausing The Video In HTML"