+ 8

Please help me with this javascript (html video player)

https://code.sololearn.com/WxW7dX94R8wB/?ref=app Hi guys , above code is such a code that I have a video tag in it When you play video ,I have added the addlistener timeupdate on it,that means every time the current video duration changes a function is called ! Then function that us called does this thing : It checks if the current video duration is greater than the 40% of the total duration then it calls other function saying : console.log("+1 added to total views") But every time if video current duration is great then the 40% of total video duration it called function again again saying +1 added But i want the function to be called only once if the video duration is greater than the 40% of total duration To make it easy 4 u guys to understand It's simple I'm calling a function if the video has been watched or current duration is greater than the 40% of total video duration then it has to called a function that adds +1 to views count But I'm using greater than it calls function multipleTime

2nd May 2021, 8:32 AM
furqan elahie
5 ответов
+ 3
Quickcoder took my words 😂 so no need to answer
2nd May 2021, 2:59 PM
Arnav Kumar [Less/Not Active]
Arnav Kumar [Less/Not Active] - avatar
+ 1
Hello, I guess removing the eventListener from the DOM-Object (the video-tag) may be the more elegant way than declaring a boolean variable and setting it to false. It would just be the line video.removeEventListener("timeupdate", myfunc) after the output to the console.
18th May 2021, 10:38 PM
Niederkofler Martin