我正在尝试使用 HTML5 和 javascript 的组合创建一种可以在 iPhone 上运行的播放列表功能。我对这个平台很陌生,我希望这里有人可以帮助我找出我的代码存在的问题。第一首歌曲正确地自动播放,但当它结束时,下一首歌曲不会加载和播放。下面提供了我网站的 javascript 代码,在此先感谢。(如果这段代码非常混乱,我深表歉意,我从 iv 学到的东西和我可以在网上找到不同的地方组装这个)
<script type="text/javascript">
var songname="Bottoms Up";
var counter=1;
var totalsongs=3;
while (counter<=totalsongs-1) {
document.write(<h2>songname</h2>);
switch (counter) {
case 1:
var nextSong="audio/Hey.mp3";
var audioPlayer=document.getElementById('audioPlayer');
audioPlayer.onend = function() {
audioPlayer.src = nextSong;
songname="Hey";
counter=(counter+1);
if(counter>totalsongs-1) {
counter=1;
} //if close
} //onend function close
case 2:
var nextSong="audio/I Like It.mp3";
var audioPlayer=document.getElementById('audioPlayer');
audioPlayer.onend = function() {
audioPlayer.src = nextSong;
songname="I Like It";
counter=(counter+1);
if(counter>totalsongs-1) {
counter=1;
} //if close
} //onend function close
} //switch close
} //while close
</script>
<center><audio src="audio/Bottoms Up.mp3" autoplay controls /></center>