Take this page for example:
<!doctype html>
<html>
<body>
<video id="video" controls width="500" muted="muted" >
<source src="https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_1920_18MG.mp4" type="video/mp4"/>
</video>
<script type="text/javascript">
var vid=document.getElementById('video')
vid.onpause=function(){
console.log('on pause executed')
}
vid.onplay=function(){
console.log('on play executed')
}
</script>
</body>
</html>
If I seek while the video is playing then both of these show up in the console. Neither show up in the console if I seek while the video is paused. How can I make it so these functions are only called when the user explicitly pauses/plays the video?
Take this page for example:
<!doctype html>
<html>
<body>
<video id="video" controls width="500" muted="muted" >
<source src="https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_1920_18MG.mp4" type="video/mp4"/>
</video>
<script type="text/javascript">
var vid=document.getElementById('video')
vid.onpause=function(){
console.log('on pause executed')
}
vid.onplay=function(){
console.log('on play executed')
}
</script>
</body>
</html>
If I seek while the video is playing then both of these show up in the console. Neither show up in the console if I seek while the video is paused. How can I make it so these functions are only called when the user explicitly pauses/plays the video?
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.