html5 play event vs playing event in video tag

六眼飞鱼酱① 提交于 2019-11-30 19:18:27

The reason for the difference is that once you click the play button (or call the play method), the paused state is false and the play event will fire, but that's no guarantee that the video will actually start playing. It's just "trying" to play.

If at any point the video doesn't have enough data, then it will appear to pause (though, again, paused will be false) and the waiting event will fire. Once there is enough data (and readyState is greater than or equal to HAVE_FUTURE_DATA), the playing event will fire and the video will resume.

So, for practical purposes, play is good for setting a visual indicator of play state, like the icon on a play/pause toggle button. Use playing if you want to know when the video is actually playing. For example, you might want to show a spinning "loading" icon when the waiting event fires, and then remove that icon when playing fires.

(Aside from not having enough data, there are are other reasons that the video will not play, even though you want it to, but those may not cause the waiting and playing events to fire. More details on that in the HTML standard.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!