gpt4 book ai didi

javascript - 暂停 youtube 视频,youtube api

转载 作者:可可西里 更新时间:2023-11-01 02:31:35 24 4
gpt4 key购买 nike

我正在尝试使用以下代码暂停和播放 YouTube 视频,该代码几乎是 Youtube API page 的副本:

// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_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 onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '315',
width: '560',
videoId: 'bpOR_HuHRNs',
});
}

Here's a demo in jsFiddle

但是,它不起作用。任何人都知道如何做到这一点?

最佳答案

播放器准备就绪后,使用 player.playVideo();(恢复)和 player.pauseVideo();(暂停):http://jsfiddle.net/4WPmY/6/

function onYouTubePlayerAPIReady() {
    player = new YT.Player('player', {
        height: '315',
        width: '560',
        videoId: 'bpOR_HuHRNs',
    });
    document.getElementById('resume').onclick = function() {
        player.playVideo();
    };
    document.getElementById('pause').onclick = function() {
        player.pauseVideo();
    };
}

关于javascript - 暂停 youtube 视频,youtube api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11283871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com