如何判断< video>元素目前正在播放? [英] How to tell if a <video> element is currently playing?
问题描述
我看到 MediaElement 界面公开了<$ c等属性$ c>暂停,寻找
,结束
。但是,从列表中遗漏的是播放
。
I see that the MediaElement interface exposes attributes like paused
, seeking
, and ended
. Missing from the list, however, is playing
.
我知道 播放
活动元素开始播放,并 timeupdate
活动事件定期播放,但我正在寻找一种方法来确定视频是否正在播放现在。有没有一种简单的方法可以确定这个?
I know there are playing
events that fire when an element starts playing, and timeupdate
events events periodically while playing, but I'm looking for a way to determine whether a video is playing right now. Is there an easy way to determine this?
我最接近的是:
!(video.paused || video.ended || video.seeking || video.readyState < video.HAVE_FUTURE_DATA)
推荐答案
没有特定的属性可以显示当前是否正在播放 MediaElement
。但是,您可以从其他属性的状态推断出这一点。如果:
There is not a specific attribute that will reveal whether a MediaElement
is currently playing. However, you can deduce this from the state of the other attributes. If:
-
currentTime
大于零, -
已暂停
为false, -
已结束
为false
currentTime
is greater than zero, andpaused
is false, andended
is false
然后该元素正在播放。
您可能还需要检查 readyState
以查看媒体是否因错误而停止。
You may also need to check readyState
to see if the media stopped due to errors.
这篇关于如何判断< video>元素目前正在播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!