From b5a2f9bb2fa04613e20c0f38ed1f5ef51658f2d8 Mon Sep 17 00:00:00 2001 From: rudywaltz Date: Wed, 25 Sep 2019 23:58:39 +0200 Subject: [PATCH] refactor(player): extract nextFromPlaylist function #23 --- src/components/Player.svelte | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/components/Player.svelte b/src/components/Player.svelte index 13f8b26..e178edc 100644 --- a/src/components/Player.svelte +++ b/src/components/Player.svelte @@ -77,23 +77,27 @@ return; } - $song = $playlist.shift(); - $playlist = $playlist; //TODO: nicer solution - currentSound = createCurrentSong(); + nextFromPlaylist(); } const nextSong = () => { + currentSound.unload(); + if (!$playlist.length) { clearPollingSong = true; resetSongStatus(); return; } - $song = $playlist.shift(); - $playlist = $playlist; //TODO: nicer solution - currentSound = createCurrentSong(); + nextFromPlaylist(); + } + const nextFromPlaylist = () => { + $song = $playlist.shift(); + $playlist = $playlist; //TODO: nicer solution + currentSound = createCurrentSong(); + } const toggleSound = () => playing ? pauseSound() : playSound(); const playSound = () => { @@ -102,7 +106,6 @@ clearPollingSong = false; const pollingSongData = setInterval(() => { - console.log('pollypirot'); if (!playing) { time = 0; clearInterval(pollingSongData);