【发布时间】:2019-04-07 05:08:55
【问题描述】:
我正在尝试从 Soundcloud 嵌入一个音频播放器,我想从白天到晚上动态更改。
HTML:
<iframe id="song" width="100%" height="20" scrolling="no" frameborder="no" allow="autoplay"></iframe>
JS:
var currentTime = new Date().getHours();
var song = document.getElementById('song');
var source = document.createElement('source');
if (6 <= currentTime && currentTime < 19) {
source.setAttribute('src', 'https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/482221002%3Fsecret_token%3Ds-ahwqc&color=%23577c5d&inverse=false&auto_play=true&show_user=true');
song.appendChild(source);
song.play();
}
else {
source.setAttribute('src', 'https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/482220933%3Fsecret_token%3Ds-dEQ64&color=%23577c5d&inverse=true&auto_play=true&show_user=true');
song.appendChild(source);
audio.play();
}
目前,音频播放器根本没有显示在页面上。对此的任何帮助将不胜感激。
【问题讨论】:
标签: javascript html css audio dynamic