html5播放事件与视频标签中的播放事件 [英] html5 play event vs playing event in video tag

查看:580
本文介绍了html5播放事件与视频标签中的播放事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关HTML5视频标记的文档,并不完全理解它。
如果用户点击播放按钮或控制栏上的播放箭头,我会认为你只有一个事件,而且该事件表明视频
正在播放。

I'm reading documentation on the HTML5 video tag and don't totally understand it. If the user clicks a play button, or the play arrow on the control bar, I would think that you have just one event, and that event would indicate that the video is playing.

但我读到:
'播放'在音频/视频开始播放或不再暂停时触发
'播放'时触发在暂停
或停止缓冲后,音频/视频已准备好播放。
听起来第二个只会在你暂停视频然后再次播放
时发生,
然后第一个发生,但也会在你第一次启动视频时发生。
但是为什么呢?
为什么不只是一个事件?

But I read that: 'play' fires when the audio/video has been started or is no longer paused 'playing' fires when the audio/video is ready to play after having been paused or stopped for buffering. It sounds like the second one only happens if you pause the video and then play it again, while the first one happens then, but also happens when you first start a video. But why do that? Why not just one event?

推荐答案

区别的原因是一旦你点击播放按钮(或调用 play 方法),暂停状态为 false 并且播放事件将触发,但不保证视频实际上会开始播放。这只是尝试播放。

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.

如果视频在任何时候没有足够的数据,那么它似乎会暂停(但是,再次,暂停将为false)并且等待事件将触发。一旦有足够的数据( readyState 大于或等于 HAVE_FUTURE_DATA ),播放事件将触发,视频将恢复。

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.

因此,出于实用目的,播放适用于设置播放状态的可视指示器,如播放/暂停切换按钮上的图标。如果您想知道视频实际播放的时间,请使用播放。例如,您可能希望在等待事件触发时显示旋转的加载图标,然后在播放时删除该图标 fires。

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.

(除了没有足够的数据,还有其他原因导致视频无法播放,即使你想要它,但那些可能不要导致等待播放事件。有关详细信息,请参阅HTML标准。)

(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.)

这篇关于html5播放事件与视频标签中的播放事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆