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>