javascript – YouTube iframe嵌入中指向特定时间的链接

前端之家收集整理的这篇文章主要介绍了javascript – YouTube iframe嵌入中指向特定时间的链接前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
可以链接到附加#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..

解决方法

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是我创造的小提琴.

猜你在找的JavaScript相关文章