Is there a way to “seek” to a certain time in a video using JavaScript?

余生长醉 提交于 2019-11-29 08:09:19

Sure. You can use VideoJS. You may have a hard time getting control of the iFrame as you put it. You can embed various video hosting sites' video with VideoJS, supposedly.

<script>
VideoJS.DOMReady(function() {
var player = VideoJS.setup("current_video");
player.play();
player.currentTime(666);
});
</script>

ref:

https://github.com/zencoder/video-js/blob/df41661f47201cfbc979b1fbba68fba3d67c06b0/dev/src/tech/youtube.js

http://videojs.com/

https://github.com/zencoder/video-js/blob/master/docs/api.md

Unless your website also has the host, protocol and port of http://player.vimeo.com, you can not run any code on the iframe's document.

Benjamin Deming

Unfortunately, not always. There is no single solution to seek a time in a Flash video if you don't know what the source of the video is.

If you ever encounter HTML5 video, you can try this: Start HTML5 video at a particular position when loading?

That iframe will give you trouble, however in general you can do this without a library.

// get the video element
let video = document.getElementsByTagName('video')[0]
// jump it to a specific time
video.currentTime = 10 // the number of seconds you want it to be at
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!