refactor ajax functions, remove default track
This commit is contained in:
parent
3382579b47
commit
b0e4b956a9
2
musik.py
2
musik.py
|
@ -50,8 +50,6 @@ def index():
|
||||||
nav_items = os.listdir(MUSIC_DIR)
|
nav_items = os.listdir(MUSIC_DIR)
|
||||||
nav_items.sort()
|
nav_items.sort()
|
||||||
nav_items = [item + '/' for item in nav_items]
|
nav_items = [item + '/' for item in nav_items]
|
||||||
initial_track = "/Accept/Accept - Balls to the Wall (1983) [FLAC] {74321 93214 2}/01 - Balls to the Wall.flac"
|
|
||||||
initial_cover = "/Accept/Accept - Balls to the Wall (1983) [FLAC] {74321 93214 2}/folder.jpg"
|
|
||||||
cd = "/"
|
cd = "/"
|
||||||
return render_template('index.html', **locals())
|
return render_template('index.html', **locals())
|
||||||
|
|
||||||
|
|
|
@ -3,23 +3,20 @@ function load() {
|
||||||
document.getElementById('player').addEventListener('ended', function() {
|
document.getElementById('player').addEventListener('ended', function() {
|
||||||
// shuffle
|
// shuffle
|
||||||
if (document.getElementById('shuffle').checked) {
|
if (document.getElementById('shuffle').checked) {
|
||||||
ajax('/musik/get_shuffle', function() {
|
var httpRequest;
|
||||||
|
httpRequest = new XMLHttpRequest();
|
||||||
|
httpRequest.onreadystatechange = function() {
|
||||||
if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; }
|
if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; }
|
||||||
if (httpRequest.status !== 200) { return; }
|
if (httpRequest.status !== 200) { return; }
|
||||||
let track = httpRequest.responseText;
|
let track = httpRequest.responseText;
|
||||||
change_track(track);
|
change_track(track);
|
||||||
});
|
};
|
||||||
|
httpRequest.open('GET', '/musik/get_shuffle', true);
|
||||||
|
httpRequest.send();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var httpRequest;
|
|
||||||
function ajax(url, func) {
|
|
||||||
httpRequest = new XMLHttpRequest();
|
|
||||||
httpRequest.onreadystatechange = func;
|
|
||||||
httpRequest.open('GET', url, true);
|
|
||||||
httpRequest.send();
|
|
||||||
}
|
|
||||||
|
|
||||||
function navigate(item) {
|
function navigate(item) {
|
||||||
if (/\..{3,5}$/.test(item)) {
|
if (/\..{3,5}$/.test(item)) {
|
||||||
|
@ -62,17 +59,20 @@ function get_dir(item) {
|
||||||
else {
|
else {
|
||||||
item = cd + item;
|
item = cd + item;
|
||||||
}
|
}
|
||||||
ajax('/musik/get_dir/' + item, update_nav_items);
|
|
||||||
}
|
|
||||||
|
|
||||||
function update_nav_items() {
|
var httpRequest;
|
||||||
if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; }
|
httpRequest = new XMLHttpRequest();
|
||||||
if (httpRequest.status !== 200) { return; }
|
httpRequest.onreadystatechange = function () {
|
||||||
nav_items = JSON.parse(httpRequest.responseText);
|
if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; }
|
||||||
document.getElementById('currentDirectory').innerText = nav_items.shift();
|
if (httpRequest.status !== 200) { return; }
|
||||||
let html_str = '';
|
nav_items = JSON.parse(httpRequest.responseText);
|
||||||
for (let i = 0; i < nav_items.length; i++) {
|
document.getElementById('currentDirectory').innerText = nav_items.shift();
|
||||||
html_str += `<li><a href="javascript:void(0);" onclick="navigate(\`${nav_items[i]}\`)">${nav_items[i]}</a></li>`;
|
let html_str = '';
|
||||||
}
|
for (let i = 0; i < nav_items.length; i++) {
|
||||||
document.getElementById('navItems').innerHTML = html_str;
|
html_str += `<li><a href="javascript:void(0);" onclick="navigate(\`${nav_items[i]}\`)">${nav_items[i]}</a></li>`;
|
||||||
|
}
|
||||||
|
document.getElementById('navItems').innerHTML = html_str;
|
||||||
|
};
|
||||||
|
httpRequest.open('GET', '/musik/get_dir/' + item, true);
|
||||||
|
httpRequest.send();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,11 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div id="playerContainer">
|
<div id="playerContainer">
|
||||||
<span id="albumCover"><img src="/musik/album_cover{{ initial_cover }}"/></span>
|
<span id="albumCover"><img src=""/></span>
|
||||||
<span id="playerControls">
|
<span id="playerControls">
|
||||||
<h3 id="nowPlaying">{{ initial_track }}</h3>
|
<h3 id="nowPlaying"></h3>
|
||||||
<audio id="player" controls>
|
<audio id="player" controls>
|
||||||
<source id="stream" src="{{ url_for('stream', track=initial_track) }}" type="audio/ogg">
|
<source id="stream" src="" type="audio/ogg">
|
||||||
</audio>
|
</audio>
|
||||||
<div>
|
<div>
|
||||||
<input type="checkbox" name="shuffle" id="shuffle" checked="true">
|
<input type="checkbox" name="shuffle" id="shuffle" checked="true">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user