hal*_*uud 12 javascript youtube youtube-api youtube-javascript-api
我正在尝试使用以下代码暂停和播放YouTube视频,这些代码几乎是Youtube API页面中的副本:
// 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',
});
}
Run Code Online (Sandbox Code Playgroud)
但是,它不起作用.任何人都知道如何做到这一点?
Rob*_*b W 21
播放器准备就绪后使用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();
};
}
Run Code Online (Sandbox Code Playgroud)