这是一些应该让您走上正轨的代码
首先是所有浏览器都支持的html音频元素,但在IE家族中只有IE9
<audio id="test" controls="controls" type="audio/ogg">Your browser doesn't support the audio tag.</audio>
然后是javascript
window.onload=function(){
var pre='';
var arr=['songTitle1','songTitle2','songTitle3'];
var ind=0;
var ele=document.getElementById('test');
ele.src=(ind++)+'.ogg';
ele.play();
//when the song ends start a new one
ele.onended=function(){
ele.src=(ind++)+'.ogg';
//if you are done with all the songs loop back to the beginning.
//Or you could add some code to load more songs from the server
ind=ind==arr.length?0:ind;
ele.play();
}
}
假设您将 ogg 文件与 html 文件放在同一目录中,这仅需要一组歌曲标题并播放它们。现在我认为 ogg 是您可以在所有浏览器上播放的唯一格式。