-
Notifications
You must be signed in to change notification settings - Fork 1
/
player.js
48 lines (44 loc) · 1.24 KB
/
player.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(function filterlist() {
var options = {
valueNames: ["chlist"]
}
var listObj = new List("test", options);
}())
var myaudio;
var playlist;
var tracks;
var current;
initaudio();
function initaudio(){
current = 0;
myaudio = $('#audio');
playlist = $('#playlist');
tracks = playlist.find('li a');
len = tracks.length - 1;
myaudio[0].volume = .90;
myaudio[0].play();
playlist.find('a').click(function(e){
e.preventDefault();
link = $(this);
current = link.parent().index();
runaudio(link, myaudio[0]);
});
myaudio[0].addEventListener('ended',function(e){
current++;
if(current == len){
current = 0;
link = playlist.find('a')[0];
}else{
link = playlist.find('a')[current];
}
runaudio($(link),myaudio[0]);
});
}
// Se cambió esta parte del código para que la función encuentre la segunda URL a través del atributo data-altsrc
function runaudio(link, player){
$(player).find('#primarysrc').attr('src', link.attr('href'));
$(player).find('#secondarysrc').attr('src', link.attr('data-altsrc'));
par = link.parent();
par.addClass('active').siblings().removeClass('active');
myaudio.load();
}