2
     <div id="ytplayer"></div>
    <script>
        // Load the IFrame Player API code asynchronously.
        var tag = document.createElement('script');
        tag.src = "https://www.youtube.com/player_api";
        var firstScriptTag = document.getElementsByTagName('script')[0];
        firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

        // Replace the 'ytplayer' element with an <iframe> and
        // YouTube player after the API code downloads.
        var player;
        function onYouTubePlayerAPIReady() {
            player = new YT.Player('ytplayer', {
                height:'390',
                width:'640',
                videoId:'A_aYVs_zFA8',
                events:{
                    'onReady':onPlayerReady,
                    'onStateChange':onPlayerStateChange
                }
            });
        }

        function onPlayerReady(event) {
            _isPlayerReady = true;
        }
        function onPlayerStateChange(event) {
            switch (event.data) {
                case YT.PlayerState.ENDED:
                $j  = jQuery.noConflict();
                $j(".vid-flow").hide();
                ShowCustomDialog();
                    break;
                case YT.PlayerState.PLAYING:
                    break;
                case YT.PlayerState.PAUSED:
                    break;
                case YT.PlayerState.BUFFERING:
                    break;
                case YT.PlayerState.CUED:
                    break;
                default:
                    break;
            }
        }


    </script>

在 JavaScript 中,我想在 'ytplayer' div 上加载一个 youtube 播放器。我正在查看此https://developers.google.com/youtube/iframe_api_reference#Operations有人知道我如何删除视频的名称。

我试图获取 iframe,但如果我执行 iframe,我的 js 代码将无法工作。因此,有人可以选择删除显示在 youtube 视频嵌入顶部的名称。

4

3 回答 3

10

http://jsfiddle.net/jXWtE/

function onYouTubePlayerAPIReady() {
    player = new YT.Player('ytplayer', {
        height: '390',
        width: '640',
        videoId: 'A_aYVs_zFA8',
        playerVars: {
            'showinfo': 0
        },
        events: {
            'onReady': onPlayerReady,
                'onStateChange': onPlayerStateChange
        }
    });
}
于 2013-01-18T18:22:46.403 回答
3

Yusaf Khaliq 有正确的答案,但是通过更改强制嵌入标签在 videoID 之后接受额外参数的方法

videoId:'A_aYVs_zFA8',

videoId:'A_aYVs_zFA8?showinfo=0&',

您应该能够以这种方式将任意数量的参数串起来,只需将它们分开即可&

于 2013-01-18T17:25:35.810 回答
1

Unfortunately, the showinfo attribute was deprecated as of September 25, 2018. This means that there is no supported mechanism to disable the information at the top of the video anymore using their API.

https://developers.google.com/youtube/player_parameters#showinfo

于 2020-04-22T04:02:08.510 回答