Youtube IFrame API - 启用 Youtube 历史记录时开始时间不起作用

问题描述 投票:0回答:1

当用户在启用了 Youtube 历史记录的情况下登录 YouTube 时,开始时间将不起作用。

不知何故,视频播放后youtube会转到历史上最后一个保存时间。

重现步骤

  1. 登录 youtube.com
  2. 转到accounts.google.com > 数据和隐私 > youtube 历史记录(打开)
  3. 运行附加的 HTML 脚本
  4. 将时间设置为2分钟左右,然后播放几秒钟
  5. 按ctrl+shift+R刷新页面

预期结果:

  • 应该在25分钟开始播放

实际结果:

  • 将播放至2分钟(或历史上最后播放时间)
<html>
<script src="https://www.youtube.com/iframe_api" type="application/javascript"></script>
<script>

    let player;
    function onYouTubeIframeAPIReady() {
        console.log('ready')
        player = new YT.Player('player', {
            sandbox: true,
            height: '390',
            width: '640',
            videoId: 'T9oT-oOaTNU',
            playerVars: {
                'playsinline': 1,
                'autoplay': 0,
                'start': 1500
            },
            events: {
                'onReady': onPlayerReady,
                'onStateChange': onPlayerStateChange
            }
        });

        player.seekTo = (n) => {
            console.log({ n });
        }
    }

    // 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.
    let done = false;
    function onPlayerStateChange(event) {
    }
    function stopVideo() {
        player.stopVideo();
    }
</script>

<body>
    <div class="responsive-embed widescreen">
        <div class="embed video-player">
            <div id="player"></div>
        </div>
    </div>
</body>

</html>
youtube-iframe-api
1个回答
0
投票

我通过将 IFrame 域更改为 www.youtube-nocookie.com 而不是 www.youtube.com 解决了这个问题:

<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/VIDEO_ID?fs=1&start=START_TIME&end=END_TIME" frameborder="0" allowfullscreen></iframe>

将 VIDEO_ID 更改为您的视频 ID,将 START_TIME 更改为您想要的开始时间,将 END_TIME 更改为结束时间,或者在我的情况下更改为开始时间。


一些背景故事: 上个月我的网站突然遇到了这个问题,以前没有发生过。

我试图向 Google 这里提交一个错误,但他们说他们无法重现它,并表示这似乎是一个浏览器问题,这与 this 2015 年的过时帖子相匹配

© www.soinside.com 2019 - 2024. All rights reserved.