如何获取YouTube视频的当前时间?
我一直在YouTube api中搜索,我只是不明白: https://developers.google.com/youtube/js_api_reference?csw=1
我一直在Stack中搜索并尝试应用他们所说的但是它不起作用。可能我错过了一些我不理解的东西:
Youtube API returning current time
Getting Current YouTube Video Time
我很感激任何指导知道从哪里开始
您可以自己检查一下:http://jsfiddle.net/twL9z8e1/
$("#bookmarkBoto").click(function() {
//var time = $("#yt").currentTime();//no
//var time = $("#yt").getCurrentTime();//no
$('#check').text(time);
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<iframe id="yt" name="yt" width="720" height="405" src="https://www.youtube.com/embed/M7lc1UVf-VE" frameborder="0" allowfullscreen></iframe>
<br><br>
<div id="bookmarkBoto">bookmarkBoto</div>
<div id="check">check</div>
&#13;
答案 0 :(得分:0)
没有样本方式,您需要使用YouTube API。这是javascript代码。我最后做了一个实例。
<强> JAVASCRIPT 强>
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', {
events: {
'onReady': onPlayerReady
}
});
}
function onPlayerReady(event) {
event.target.playVideo();
}
$('button').click(function() {
console.log(player.getCurrentTime())
})
<强> HTML 强>
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<iframe id="player" width="640" height="360" src="https://www.youtube.com/embed/zua0_IXcPFY?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
<button>click time</button>
</body>
</html>