通过 seekTo() 链接到 youtube 视频中的特定时间; [英] Link to specific time in a youtube video via seekTo();

查看:36
本文介绍了通过 seekTo() 链接到 youtube 视频中的特定时间;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取类似于 youtube 视频的索引页面的内容,以便提供指向视频特定时间的链接.我尝试按照 链接到 YouTube iframe 嵌入中的特定时间,但不知何故它似乎不起作用.这是我的代码:

I’m trying to get something like an index page of a youtube video so that there are links to specific times of the video. I tried it to do like explained in Links to Specific Times in YouTube iframe embed, but somehow it doesnt seem to work. This is my code:

<script>
    var tag = document.createElement('script');
    tag.src = "//www.youtube.com/player_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

    var player;
    function onYouTubePlayerAPIReady() {
        player = new YT.Player('video', { events: {'onReady': onPlayerReady}});
    }

    function playerSeekTo(seconds) {
        player.seekTo(seconds);
    }
</script>

HTML:

<iframe src="https://www.youtube.com/embed/FKWwdQu6_ok?enablejsapi=1" frameborder="0" allowfullscreen id="video">
</iframe>

<a href="#" onclick="playerSeekTo(70); return false;">Link to 1 minutes 10 seconds</a>
<a href="#" onclick="playerSeekTo(90); return false;">Link to 1 minutes 30seconds</a>
<a href="#" onclick="playerSeekTo(110); return false;">Link to 1 minutes 50 seconds</a>

推荐答案

我遇到了三个问题:

tag.src = "//www.youtube.com/player_api";

导致错误.应该

tag.src = "http://www.youtube.com/player_api";

第二个

player = new YT.Player('video', { events: {'onReady': onPlayerReady}});

显然,onPlayerReady 没有定义.当您删除此部分时,它会正常工作.你想通过这个实现什么?

Obviously, onPlayerReady is not defined. When you remove this part, it'll work fine. What do you want to achieve with this?

player = new YT.Player('video');

(第三个)

对我来说,您嵌入的视频不可用.当我嵌入另一个视频(例如 Im69kzhpR3I)时,一切正常.

(3rd)

To me, the video you embed is not available. When I embed another video (e.g. Im69kzhpR3I), everything behaves as it should.

这篇关于通过 seekTo() 链接到 youtube 视频中的特定时间;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆