update ui with track info

This commit is contained in:
iou1name 2024-12-20 23:35:25 -05:00
parent c859c4ff9b
commit 8238288df6

View File

@ -35,7 +35,7 @@ function init() {
}
});
init_analyzer();
//init_analyzer();
}
async function get_rand_track() {
@ -47,6 +47,7 @@ async function get_rand_track() {
async function nextTrack() {
track = await get_rand_track();
player.src = track.source;
update_now_playing(track);
playTrack();
}
@ -60,7 +61,6 @@ async function playTrack() {
}
player.play();
navigator.mediaSession.playbackState = "playing";
setMediaSession(track);
document.querySelector("#play-btn").style.display = "none";
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() {
if (!player.duration){return;}
navigator.mediaSession.setPositionState({
duration: Math.floor(player.duration),
playbackRate: player.playbackRate,
position: Math.floor(player.currentTime)
});
analyser.getByteTimeDomainData(audio_data);
//analyser.getByteTimeDomainData(audio_data);
document.querySelector('#seek-slider').value = Math.floor(player.currentTime);
display_current_time();
@ -144,7 +153,7 @@ function volume_restore() {
}
function init_analyzer() {
let audioCtx = new AudioContext();
audioCtx = new AudioContext();
analyser = audioCtx.createAnalyser();
let source = audioCtx.createMediaElementSource(player);