循环选项在youtube js api中不起作用

时间:2013-11-05 17:24:56

标签: javascript api loops youtube

我想知道为什么我的代码不播放视频循环。除了循环选项外,一切正常。我真的需要它。非常感谢。

<script src="jsapi.js"></script>
<script src="swfobject.js"></script>
<div id="ytapiplayer">You need Flash player 8+ and JavaScript enabled to view this video.</div>
<script type="text/javascript">
    google.load("swfobject", "2.1");
    function onYouTubePlayerReady(playerId) {
        ytplayer = document.getElementById("myytplayer");
        ytplayer.playVideo();
        ytplayer.mute();
    // I've tried it, just to.. try hehe  ytplayer.setLoop(true);
    }
    var params = { allowScriptAccess: "always" };
    var atts = { id: "myytplayer" };
    swfobject.embedSWF("http://www.youtube.com/v/RLOQCqGKVt8?autoplay=1&loop=1&enablejsapi=1&playerapiid=ytplayer&allowFullScreen=true&version=3&controls=0&showinfo=0&autohide=1&rel=0",
    "ytapiplayer", "100%", "100%", "8", null, null, params, atts);
</script>

1 个答案:

答案 0 :(得分:14)

解决方案是添加“玩家变速器”&#39;对象,播放列表&#39;属性。 像这个循环一样,也适用于单个视频。

function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
        height: '100%',
        width: '100%',
        playerVars : {
                  'autoplay' : 1,
                  'rel' : 0,
                  'showinfo' : 0,
                  'showsearch' : 0,
                  'controls' : 0,
                  'loop' : 1,
                  'enablejsapi' : 1,
                  'playlist': 'your-single-video-ID'
                },
        videoId: 'your-single-video-ID',
        events: {
            'onReady': onPlayerReady
            }
       });
}