简体   繁体   English

如何正常停止html5视频播放

[英]How to gracefully stop html5 video playback

Is there a way to cleanly stop the html5 video playback ? 有没有办法彻底停止html5视频播放?

There are options like: 有如下选项:

Set videoElement.src = "" . 设置videoElement.src =“”。 This throws an error on the video element, with code = 4. 这会在视频元素上引发错误,代码为4。

OR 要么

call videoElement.load(). 调用videoElement.load()。 This sets the readyState = 0 but there is not much documentation around it. 这将readyState设置为0,但是周围没有太多文档。

UX Perspective UX透视

Looking on Google for the difference between pause and stop gave me various results which I can summrize as: 在Google上查找暂停和停止之间的区别会给我带来各种结果,我可以总结为:

Pause : Playback is stopped. 暂停 :播放停止。 Hitting play again continues from last position. 从最后位置继续打球。
Stop : Playback is stopped. 停止 :播放停止。 Hitting play again continues from beginning 从头开始继续击球

At least from the UX point of view that covers all grounds 至少从UX的角度来看,它涵盖了所有方面

Stopping of loading of media 停止加载媒体

If your real goal is to stop the buffering process from happening as well, then your current approach seems to be entirely correct, running the following code is not triggering any errors for me in any browser I tried. 如果您的真正目标是也停止缓冲过程,那么您当前的方法似乎是完全正确的,运行以下代码不会对我尝试使用的任何浏览器触发任何错误。

 var video = document.querySelector("video"); video.play(); setTimeout(function() { video.pause(0); video.setAttribute("src", ""); }, 5000); 
 <video id="video" controls="" preload="none" mediagroup="myVideoGroup" poster="http://media.w3.org/2010/05/sintel/poster.png" style="height:180px"> <source id="mp4" src="http://media.w3.org/2010/05/sintel/trailer.mp4" type="video/mp4"> <source id="webm" src="http://media.w3.org/2010/05/sintel/trailer.webm" type="video/webm"> <source id="ogv" src="http://media.w3.org/2010/05/sintel/trailer.ogv" type="video/ogg"> </video> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM