YouTube 嵌入:自动以 1080p 格式播放



您曾经能够这样做以使嵌入式YouTube视频以1080p(或其他质量(自动播放,但是,这不再有效。

有没有另一种最新的方法来实现这一目标?

您可以使用此处的 iframe API:

https://developers.google.com/youtube/iframe_api_reference

使用 API,您可以在嵌入式视频准备就绪后指定播放质量,如下例所示:

<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: 'INSERT_VIDEO_ID_HERE',
            events: {
                'onReady': onPlayerReady
            }
        });
    }
    // 4. The API will call this function when the video player is ready.
    // In this case we set the playback quality to 1080p
    function onPlayerReady(event) {
        event.target.setPlaybackQuality('hd1080')
    }
</script>

相关内容

  • 没有找到相关文章

最新更新