是否可以将getTime()函数链接到视频或youtube视频?
例如,如果我的时钟是下午14:30:02,那么我的视频应该在14:30:02开始播放。如果可能的话,我将如何进行?
非常感谢!
function checkTime() {
if (player.getCurrentTime() >= 20) {
console.log("Played 20 sec");
}
else
window.setTimeout(checkTime, 100);
}
window.setTimeout(checkTime, 100);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
答案 0 :(得分:1)
您可以在特定时间加载视频iframe,我认为您无法对外部元素进行任何其他形式的控制。
var thetime = new Date('November 13, 2018 14:49:00')
var msuntillhappens = thetime.getTime() - new Date().getTime();
setTimeout(function(){
console.log("It's time!")
$('#frame').html('<iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ?autoplay=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>');
}, msuntillhappens);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="frame"></div>
如果要在特定时间开始播放YouTube视频,可以在框架URL中添加一个?start=x
参数以播放具有给定偏移量的视频。根据您的需要,您可以从当前客户时间或其他任何时间中获得此金额。其他视频托管平台可能具有不同的参数。
有关Date
对象的更多信息,请随时参考this。
编辑:您也可以使用YouTube iframe API,将其与上面的代码混合,并使用相应的API方法,而不是直接插入iframe html。