html5播放事件与视频标签中的播放事件

编程入门 行业动态 更新时间:2024-10-26 08:24:20
本文介绍了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播放事件与视频标签中的播放事件

本文发布于:2023-07-13 03:16:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1099776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事件   标签   视频

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!