This article introduces how to determine whether an HTML5 video is playing on YouTube using the JavaScript programming language.
Checking if an HTML5 video is playing with an if statement.
Object.defineProperty(HTMLMediaElement.prototype, 'playing', {
get: function(){
return !!(this.currentTime > 0 && !this.paused && !this.ended && this.readyState > 2);
}
})
if(document.querySelector('#movie_player > div.html5-video-container > video').playing){
console.log('true') ;
}
Summary
This time we introduced how to determine whether an HTML5 video is playing using the Object.defineProperty method.