带有<音频>JavaScript
Playlist with <audio> JavaScript
我正在创建一个个人小网站,我想在上面播放一些歌曲
<script type="text/javascript">
var i=1;
var nextSong= "";
var audioPlayer = document.getElementById('audio');
audioPlayer.onended = function(){
i++
nextSong = "Music/"+i+".mp3";
audioPlayer.src = nextSong;
audioPLayer.load();
audioPlayer.play();
if(i == 37) // this is the end of the songs.
{
i = 1;
}
}
</script>
<audio id="audio" src="Music/1.mp3"controls="controls" autoplay="autoplay" align=""> </audio>
然而,我无法让它发挥作用。它只播放第一首歌,不执行JS。例如,我尝试过提醒i
的状态,但它没有任何作用。
试试这个:
<script type="text/javascript">
var i=1;
var nextSong= "";
function setup() {
document.getElementById('audio').addEventListener('ended', function(){
i++;
nextSong = "Music/"+i+".mp3";
audioPlayer = document.getElementById('audio');
audioPlayer.src = nextSong;
audioPLayer.load();
audioPlayer.play();
if(i == 37) // this is the end of the songs.
{
i = 1;
}
}, false);
}
</script>
<body onLoad="setup();">
<audio id="audio" src="Music/1.mp3"controls="controls" autoplay="autoplay" align=""> </audio>
</body>
需要对此答案进行修改。你还需要识别音频播放器,否则这将不起作用。。。
<script type="text/javascript">
function setup() {
var i=1;
var nextSong= "";
audioPlayer = document.getElementById('audio');
document.getElementById('audio').addEventListener('ended', function(){
i=i+1;
nextSong = "m"+i+".mp3";
audioPlayer.src = nextSong;
audioPlayer.load();
audioPlayer.play();
}, false);
}
</script>
<body onLoad="setup();">
<audio id="audio" src="m1.mp3" controls="controls" autoplay="autoplay" align=""> </audio>
</body>
var i=1;var nextSong=";function setup(){document.getElementById('audio').addEventListener('ended',function(){i++;nextSong="Music/"+i+".mp3";audioPlayer=document.getElement ById('audio');audioPlayer.src=nextSong;audioPlayer.load();audidPlayer.play();if(i==37)//这是歌曲的结尾。{i=1;},false);}
相关文章:
- 为什么要使用0>javascript中的0
- 可以<脚本类型=“;text/javascript”>window.location=“/"</
- 图像可以从源<img src=""/>.TEXT可以在没有javascript的情况下从外部
- W3验证器->使用<脚本类型=“;text/javascript”>在html的正文中
- jQuery/Javascript>on单击将文本放置在最后一个已知的光标位置
- 在HTML中嵌套引号>JavaScript>WebForms或如何在JavaScript方法中调用.NET方
- 使用加载时的Codeigner动态javascript->看法
- JavaScript>on更改输入&选择更新文本区域
- javascript->php加密解密-需要澄清和方法请
- Titanium SDK:JavaScript->滚动功能不起作用
- 运动>Javascript>Hamming练习:获得'undefined不是函数'错误
- Javascript>操作员未在Extension中工作
- Java/Javascript->多个用户在同一个sql数据源上工作,必须在前端保持一致
- Javascript-->iframe使用postMessage方法调整大小
- php heredoc--不回显'<脚本类型=“;text/javascript”>'
- <脚本类型='text/javascript'>并且<脚本>
- Youtube嵌入有错误的开始时间<iframe><javascript>
- <脚本类型=";text/javascript">进入iframe
- Javascript>将结果形成为";记住";用户>避免两次展示形式
- 未定义使用Javascript->Actionscript