可以链接到附加#t=1m49s
语法的YouTube视频中的特定时间。
是否可以在嵌入的同一页面上设置链接,使视频在视频中跳转到不同的时间?
<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..
答案 0 :(得分:8)
Goran发布了api参考。我建议检查一下。以下是您正在寻找的一些基本代码。我评论了主要部分:
<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>
现在是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是我创造的小提琴。
答案 1 :(得分:3)
虽然我没有使用emdedded YouTube视频实施javascript的个人经验,但我知道YouTube有一个JavaScript API来执行此类操作。您要查找的功能是.seekTo()
http://code.google.com/apis/youtube/js_api_reference.html#seekTo
有一个漂亮的小演示here。
答案 2 :(得分:2)
使用?start=xyz
(秒)
例如:
<iframe src="http://www.youtube.com/embed/vDFuzhnTegc?start=1778" width="420" height="235"></iframe>