我有一个网站,我需要一段音频才能在美国东部时间晚上11:57 pm自动开始在网站上播放。
最好的方法是什么?倒计时时钟?如果是这样,我该怎么做?
答案 0 :(得分:0)
每天晚上11:57:00播放的简单音频
我做了一个粘时钟&把时间限制在一起......并且每天在所需的时间重复音频播放事件
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById('txt').innerHTML =
h + ":" + m + ":" + s;
if(document.getElementById('txt').innerHTML == "23:57:00"){
PLayAudio();
};
var t = setTimeout(startTime, 500);
}
function checkTime(i) {
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
function PLayAudio(){
var x = document.getElementById("myAudio");
x.play()
}
<body onload="startTime()">
<p>Audio will play at 11:57 pm !!!!</p>
<div id="txt"></div>
<audio id="myAudio" controls>
<source src="https://www.w3schools.com/html/horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>