【问题标题】:Black borders in YouTube player - Javascript APIYouTube 播放器中的黑色边框 - Javascript API
【发布时间】:2015-09-28 14:05:47
【问题描述】:

根据Getting Started 提供的示例,我正在使用YouTube Player API 添加一个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>

【问题讨论】:

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


    【解决方案1】:

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

    当您不显示控件时,使用标准尺寸(640x360)

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

    【讨论】:

    • 我认为控件不会占用任何空间。它们出现在视频中。问题是视频没有在容器(iframe)中拉伸。我正在寻找可以与 API 一起使用的“yt:stretch=16:9”、“yt:crop=16:9”之类的东西。 youtube-global.blogspot.ro/2009/04/release-notes-43009.html 或者可以让我更改 iframe 内的视频元素的东西。
    • 控件不占用空间,您的示例添加了一些空间
    猜你喜欢
    • 2014-07-09
    • 2011-10-06
    • 1970-01-01
    • 1970-01-01
    • 2015-07-09
    • 2014-11-12
    • 1970-01-01
    • 2020-12-05
    • 1970-01-01
    相关资源
    最近更新 更多