YouTube播放器中的黑色边框 - Javascript API

时间:2015-07-10 00:00:10

标签: javascript iframe youtube youtube-api youtube-javascript-api

我根据YouTube Player API 提供的示例,使用Getting Started添加YouTube视频。

黑色边框(顶部和底部)是我的问题。在YouTube Player Parameters上,我找不到可以解决问题的参数。

有没有办法隐藏黑色边框,没有CSS?

这是我使用的代码(我只在新的YT.Player中添加了playerVars):

<!--1.The <iframe> (and video player)will replace this <div> tag.-->
<div id = "player">  <  div>

 <script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');

tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
        height : '390',
        width : '640',
        videoId : 'St_dIV8NIoc',
        //
        // here is where youtube player parameters are placed
        //
        playerVars : {
            controls : 0,
            cc_load_policy : 0,
            loop : 1,
            autoplay: 1,
            modestbranding: 0,
            rel: 0,
            showinfo: 0
        },
        events : {
            'onReady' : onPlayerReady,
            'onStateChange' : onPlayerStateChange
        }
    });
}

// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
    event.target.playVideo();
}

// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
    if (event.data == YT.PlayerState.PLAYING && !done) {
        setTimeout(stopVideo, 6000);
        done = true;
    }
}
function stopVideo() {
    player.stopVideo();
}
    </script>

1 个答案:

答案 0 :(得分:1)

该示例将30px添加到标准高度(对于控件)。

如果您没有显示控件,请使用标准尺寸(640x360)

标准尺寸列于https://developers.google.com/youtube/iframe_api_reference#Playback_quality