Sheehan Alam
Sheehan Alam

Reputation: 60899

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

I have an iframe with a video, for example:

<iframe src="http://player.vimeo.com/video/18150336" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

The source won't always be vimeo, it can be YouTube, BrightCove, Hulu etc etc.

Is there a way to use jQuery/JavaScript to "seek" to a certain time in the video? For example, if I wanted to get to 3:41 inside of a video could I write code to automatically seek to that time w/o API access to the sites providing the video?

Upvotes: 3

Views: 17922

Answers (4)

Jeff Hykin
Jeff Hykin

Reputation: 2627

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

Upvotes: 3

edwardsharp
edwardsharp

Reputation: 1242

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

Upvotes: 11

alex
alex

Reputation: 490323

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.

Upvotes: 1

Benjamin Deming
Benjamin Deming

Reputation: 138

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?

Upvotes: 0

Related Questions