It is possible to link to a specific time in a YouTube video appending the #t=1m49s
syntax.
Is it possible to have links on the same page of the embed that make the video jump to different times in the video?
<a href="">Link to 1 minutes 10 seconds</a>
<a href="">Link to 3 minutes 4 seconds</a>
<a href="">Link to 5 minutes 10 seconds</a>
etc..
It is possible to link to a specific time in a YouTube video appending the #t=1m49s
syntax.
Is it possible to have links on the same page of the embed that make the video jump to different times in the video?
<a href="">Link to 1 minutes 10 seconds</a>
<a href="">Link to 3 minutes 4 seconds</a>
<a href="">Link to 5 minutes 10 seconds</a>
etc..
Share
Improve this question
edited Feb 9, 2012 at 0:35
bookcasey
asked Feb 3, 2012 at 17:47
bookcaseybookcasey
40.5k13 gold badges81 silver badges94 bronze badges
3 Answers
Reset to default 9 +50Goran has posted the api reference. I would recommend checking that out. Here is some basic code for what you're looking for though. I've commented the main parts:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script>
//this function gets called when the player is ready
function onYouTubePlayerReady (playerId) {
ytplayer = document.getElementById("myytplayer");
console.log(ytplayer);
}
//generic seekTo function taking a player element and seconds as parameters
function playerSeekTo(player, seconds) {
player.seekTo(seconds);
}
</script>
<div id="ytapiplayer">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>
<br/>
<a href="#" onclick="playerSeekTo(ytplayer, 70); return false;">Link to 1 minutes 10 seconds</a>
<a href="#" onclick="playerSeekTo(ytplayer, 90); return false;">Link to 1 minutes 30seconds</a>
<a href="#" onclick="playerSeekTo(ytplayer, 110); return false;">Link to 1 minutes 50 seconds</a>
Now the js:
var ytplayer;
$(document).ready(function() {
swfobject.embedSWF("//www.youtube.com/e/Py_IndUbcxc?enablejsapi=1&playerapiid=ytplayer &version=3",
"ytapiplayer", // where the embedded player ends up
"425", // width
"356", // height
"8", // swf version
null,
null, {
allowScriptAccess: "always"
}, {
id: "myytplayer" // here is where the id of the element is set
});
});
Here is the fiddle that I created.
Although I have no personal experience in implementing javascript with emdedded YouTube videos, I do know that YouTube have a JavaScript API to perform such actions. The function you are looking for is .seekTo()
http://code.google.com/apis/youtube/js_api_reference.html#seekTo
With a nifty little demo here.
Use ?start=xyz
(seconds)
For example:
<iframe src="http://www.youtube.com/embed/vDFuzhnTegc?start=1778" width="420" height="235"></iframe>