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..
Goran 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With