Skip to content

Commit

Permalink
fix progress
Browse files Browse the repository at this point in the history
  • Loading branch information
royalfig committed Aug 9, 2023
1 parent 8052c00 commit 090dea0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion assets/js/app/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function createPlaylist() {
const coverArtcontainer = document.querySelector('.sm-playlist-cover-art');
let nIntervId;
let prevSong;
let isPlaying = false;
const tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';

Expand Down Expand Up @@ -116,7 +117,10 @@ export default function createPlaylist() {
});

function showSongProgress() {
handleSongProgress(player, parseSeconds);
if (isPlaying) {
handleSongProgress(player, parseSeconds);
window.requestAnimationFrame(showSongProgress);
}
}

function onPlayerReady() {
Expand Down Expand Up @@ -151,10 +155,12 @@ export default function createPlaylist() {

function onPlayerStateChange(event) {
if (event.data === 2) {
isPlaying = false;
window.cancelAnimationFrame(nIntervId);

setSongState(false);
} else if (event.data === 1) {
isPlaying = true;
setSongState(true, player);

if (nIntervId) {
Expand All @@ -167,6 +173,7 @@ export default function createPlaylist() {
prevSong.parentElement.classList.remove('sm-active');
}
} else {
isPlaying = false;
window.cancelAnimationFrame(nIntervId);
}
}
Expand Down

0 comments on commit 090dea0

Please sign in to comment.