update ui with track info
This commit is contained in:
parent
c859c4ff9b
commit
8238288df6
|
@ -35,7 +35,7 @@ function init() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
init_analyzer();
|
//init_analyzer();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function get_rand_track() {
|
async function get_rand_track() {
|
||||||
|
@ -47,6 +47,7 @@ async function get_rand_track() {
|
||||||
async function nextTrack() {
|
async function nextTrack() {
|
||||||
track = await get_rand_track();
|
track = await get_rand_track();
|
||||||
player.src = track.source;
|
player.src = track.source;
|
||||||
|
update_now_playing(track);
|
||||||
playTrack();
|
playTrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +61,6 @@ async function playTrack() {
|
||||||
}
|
}
|
||||||
player.play();
|
player.play();
|
||||||
navigator.mediaSession.playbackState = "playing";
|
navigator.mediaSession.playbackState = "playing";
|
||||||
setMediaSession(track);
|
|
||||||
|
|
||||||
document.querySelector("#play-btn").style.display = "none";
|
document.querySelector("#play-btn").style.display = "none";
|
||||||
document.querySelector("#pause-btn").style.display = "initial";
|
document.querySelector("#pause-btn").style.display = "initial";
|
||||||
|
@ -92,14 +92,23 @@ function setMediaSession(track) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function update_now_playing(track) {
|
||||||
|
document.querySelector('#now_playing_artist').textContent = track.artist;
|
||||||
|
document.querySelector('#now_playing_album').textContent = track.album;
|
||||||
|
document.querySelector('#now_playing_title').textContent = track.title;
|
||||||
|
document.querySelector('#cover_art').firstChild.src = track.artwork[0].src;
|
||||||
|
setMediaSession(track);
|
||||||
|
}
|
||||||
|
|
||||||
function update_position() {
|
function update_position() {
|
||||||
|
if (!player.duration){return;}
|
||||||
navigator.mediaSession.setPositionState({
|
navigator.mediaSession.setPositionState({
|
||||||
duration: Math.floor(player.duration),
|
duration: Math.floor(player.duration),
|
||||||
playbackRate: player.playbackRate,
|
playbackRate: player.playbackRate,
|
||||||
position: Math.floor(player.currentTime)
|
position: Math.floor(player.currentTime)
|
||||||
});
|
});
|
||||||
|
|
||||||
analyser.getByteTimeDomainData(audio_data);
|
//analyser.getByteTimeDomainData(audio_data);
|
||||||
|
|
||||||
document.querySelector('#seek-slider').value = Math.floor(player.currentTime);
|
document.querySelector('#seek-slider').value = Math.floor(player.currentTime);
|
||||||
display_current_time();
|
display_current_time();
|
||||||
|
@ -144,7 +153,7 @@ function volume_restore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function init_analyzer() {
|
function init_analyzer() {
|
||||||
let audioCtx = new AudioContext();
|
audioCtx = new AudioContext();
|
||||||
analyser = audioCtx.createAnalyser();
|
analyser = audioCtx.createAnalyser();
|
||||||
let source = audioCtx.createMediaElementSource(player);
|
let source = audioCtx.createMediaElementSource(player);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user