I have written this code in HTML5 video to play around with the time functionality. If I set this line of code as
if(vid.currentTime > 5){
vid.pause();
}
the video will automatically pause, which is what i want. But if I set it as
if(vid.currentTime == 5){
vid.pause();
}
it refuses to pause and I want it to pause at different times in order to fire different actions. I don't know why. I have researched and tried to google similar situation but no luck. Any help will be appreciated. Here is the full code:
window.onload = init;
let vid;
function init() {
vid = document.querySelector("#myPlayer");
vid.ontimeupdate = displayTimeWhileVideoIsPlaying;
}
function playVideo() {
vid.play();
}
function pauseVideo() {
vid.pause();
}
function rewindVideo() {
vid.currentTime = 0
}
function displayTimeWhileVideoIsPlaying(evt) {
console.log(vid.currentTime);
ccc = 5;
if(vid.currentTime > 5){
vid.pause();
}
}
This is the link to my codepen for a working demo:
https://codepen.io/Okezie/pen/xWOLQd?editors=1011
The issue is presumably on line 28 of my code pen.