我正在尝试播放播放列表中的音乐。我喜欢这个
简单播放器
<audio id="audio" preload="auto" tabindex="0" controls="" type="audio/mpeg">
<source type="audio/mp3" src="music/demo.mp3">
Sorry, your browser does not support HTML5 audio.
</audio>
播放列表
<ul id="playlist">
<?php if($lists) { foreach ($lists as $key=> $list) { ?>
<li class="active">
<a src="music/<?php echo $list; ?>.mp3">
<?php echo $list; ?> </a>
</li>
<?php }}?>
</ul>
的JavaScript
var audio;
var playlist;
var tracks;
var current;
init();
function init(){
current = 0;
audio = $('audio');
playlist = $('#playlist');
tracks = playlist.find('li a');
len = tracks.length - 1;
playlist.find('a').click(function(e){
e.preventDefault();
link = $(this);
current = link.parent().index();
run(link, audio[0]);
});
audio[0].addEventListener('ended',function(e){
if(current == len){
current = 0;
link = playlist.find('a')[0];
}else{
current++;
link = playlist.find('a')[current];
run($(link),audio[0]);
}
});
}
function run(link, player){
player.src = link.attr('src');
par = link.parent();
par.addClass('active').siblings().removeClass('active');
audio[0].load();
audio[0].play(); }
不幸的是,播放列表点击事件仅适用于Firefox和Chrome,但不适用于IE,Safari和Opera。如何解决?
答案 0 :(得分:0)
您是否尝试将href
代替src
用于<a>
代码?