如何判断< video>元素目前正在播放? [英] How to tell if a <video> element is currently playing?

查看:120
本文介绍了如何判断< video>元素目前正在播放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到 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, and
  • paused is false, and
  • ended is false

然后该元素正在播放。

您可能还需要检查 readyState 以查看媒体是否因错误而停止。

You may also need to check readyState to see if the media stopped due to errors.

这篇关于如何判断&lt; video&gt;元素目前正在播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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