【发布时间】:2018-04-29 00:16:39
【问题描述】:
我想在网站上播放一首随机歌曲。曲调很短(最多几秒钟,它们不需要预加载或缓冲)。
这部分有效,歌曲数量可能不限,因为tunes.length会自动统计所有歌曲。
document.write在屏幕上显示随机歌曲网址的网址
tunes = new Array(
'"http://example.net/abcd.ogg"',
'"http://example.net/efgh.ogg"',
'"http://example.net/ijkl.ogg"'
)
var audiopath = (tunes[Math.floor(Math.random() * tunes.length)])
document.write (audiopath)
当 URL 被定义为常量时,这部分也可以工作。
var song = new audio('http://example.net/abcd.ogg');
song.play();
当我尝试将常量 URL 替换为变量 audiopath 时,它无法播放。
语法可能有什么问题吗?
我尝试在 URL '"@987654321@"' 或 "@987654322@" 中使用和不使用单引号运行它
var song = new audio(audiopath);
song.play();
【问题讨论】:
标签: javascript audio random shuffle