3 "FLAC": "audio/x-flac",
9 var audio
, details
, start
, prev
, data
;
10 var hash_to_id
= {}, inhibit_handle_hash
= false;
13 function load_song (id
) {
14 audio
.style
.display
= "inline";
16 var old_sources
= document
.getElementsByTagName("source");
17 while(old_sources
.length
)
18 old_sources
[0].parentNode
.removeChild(old_sources
[0]);
20 for (var i
= 0 ; i
< song
.formats
.length
; i
++){
21 var source
= document
.createElement("source");
22 var type
= TYPES
[song
.formats
[i
].format
];
23 source
.setAttribute("type", type
);
24 source
.setAttribute("src", song
.formats
[i
].file
);
25 audio
.appendChild(source
);
28 details
.innerHTML
= "Now playing: " + song
.artist
+ " - " + song
.title
;
29 inhibit_handle_hash
= true;
30 location
.hash
= song
.hash
;
31 inhibit_handle_hash
= false;
35 function play_random () {
36 start
.innerHTML
= "Next";
37 var id
= Math
.floor(Math
.random() * data
.length
);
40 prev
.disabled
= false;
45 function play_random_after_error () {
46 hist
.pop(); /* Purge offending song from history */
50 function play_prev () {
52 var song
= hist
[hist
.length
- 1];
53 console
.log("Will now play: " + song
)
60 function handle_hash(first_run
){
61 if(!hash_to_id
.hasOwnProperty(location
.hash
) || inhibit_handle_hash
)
63 var id
= hash_to_id
[location
.hash
]
64 if(first_run
=== true)
67 start
.innerHTML
= "Next";
71 window
.onload = function () {
72 var container
= document
.getElementById("player");
73 container
.innerHTML
= '<div id="details"></div> <button id="prev_player">Previous</button><button id="start_player">Play a random song</button> (or click a song title)<br><audio id="audio" controls></audio>';
74 audio
= document
.getElementById("audio");
75 details
= document
.getElementById("details");
76 start
= document
.getElementById("start_player");
77 prev
= document
.getElementById("prev_player")
81 var trs
= document
.querySelectorAll("tbody tr");
82 for (var i
= 0 ; i
< trs
.length
; i
++) {
85 "artist": tr
.getElementsByClassName("artist")[0].textContent
,
86 "title": tr
.getElementsByClassName("title")[0].textContent
,
87 "hash": tr
.getElementsByTagName("a")[0].dataset
.hash
,
90 var formats
= tr
.getElementsByClassName("formats")[0].getElementsByTagName("a");
91 for (var j
= 0 ; j
< formats
.length
; j
++) {
92 var format
= formats
[j
];
94 "format": format
.textContent
,
95 "file": format
.getAttribute("href")
99 hash_to_id
[song
.hash
] = i
;
102 audio
.style
.display
= "none";
103 audio
.addEventListener('ended', play_random
);
104 audio
.addEventListener('error', play_random_after_error
);
105 start
.addEventListener('click', play_random
);
106 prev
.addEventListener('click', play_prev
);
107 window
.onhashchange
= handle_hash
;
This page took 0.027066 seconds and 4 git commands to generate.