使用 jQuery 检测 HTML5 视频播放/暂停状态
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12027092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Detecting HTML5 video play/pause state with jQuery
提问by Jules
I'm building a jQuery slideshow which will feature an HTML5 video player on one of the slides. Is there any way to get the jQuery slideshow to pause from its otherwise automatically running state, when it detects that the video is playing, besides a "slideshow play/pause" button?
我正在构建一个 jQuery 幻灯片,它将在其中一张幻灯片上显示 HTML5 视频播放器。除了“幻灯片播放/暂停”按钮之外,有什么方法可以让 jQuery 幻灯片从其自动运行状态暂停,当它检测到视频正在播放时?
回答by jeff
You can check if the video is paused used the paused
property:
您可以使用paused
属性检查视频是否暂停:
$("#videoID").get(0).paused;
You can pause a video using the pause()
method:
您可以使用以下pause()
方法暂停视频:
$("#videoID").get(0).pause();
You can then resume the playback of the video using the play()
method:
然后,您可以使用以下play()
方法恢复视频的播放:
$("#videoID").get(0).play();
回答by Luke Robertson
var video = $('video');
var videoElement = video.get(0);
if (!videoElement.paused) {}
One way of doing it using Jquery
使用 Jquery 的一种方法