Html5 replay event vs game event in video tag

I am reading the HTML5 tag documentation and don't understand it completely. If the user presses the play button or the play arrow on the control panel, I would think that you have only one event, and this event indicates that the video is playing.

But I read that: "play" is triggered when the audio / video has been started or is no longer paused; the "game" is triggered when the audio / video is ready to play after a pause or stopped for buffering. It seems that the second only happens when you pause the video and then play it again, while the first happens then, but also happens when you first start the video. But why do this? Why not just one event?

+4
source share
1 answer

The reason for the difference is that after pressing the play button (or calling the play method), the paused state is false and the play event is triggered, but this does not guarantee that the video will start playing. He is just β€œtrying” to play.

If at some point the video is not enough data, then it will be paused (although paused again will be false) and the waiting event will occur. When there is enough data (and readyState greater than or equal to HAVE_FUTURE_DATA ), the playing event will occur and the video will resume.

So, for practical purposes, play is good for setting up a visual indicator of the playback status, for example, the icon on the play / pause button. Use playing if you want to know when the video actually plays. For example, you might want to display a rotating loading icon when the waiting event fires, and then remove that icon when playing triggered.

(Besides the fact that you don’t have enough data, there are other reasons why the video will not play, even if you want it, but it may not cause the waiting and playing events to fire. This is in the HTML standard .)

+15
source

All Articles