From c65d3ea514221e03440dfc12739618ff9b25879c Mon Sep 17 00:00:00 2001 From: Baraa Al-Masri Date: Thu, 4 Jul 2024 23:01:21 +0300 Subject: [PATCH 1/6] chore(player): update usages of audio player's source --- app/static/js/player.js | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/app/static/js/player.js b/app/static/js/player.js index bf11835..c7dee08 100644 --- a/app/static/js/player.js +++ b/app/static/js/player.js @@ -217,10 +217,8 @@ function playPauser(audioEl) { */ function stopper(audioEl) { return () => { - if (!audioEl.paused) { - audioEl.pause(); - audioEl.currentTime = 0; - } + audioEl.pause(); + audioEl.currentTime = 0; const songEl = document.getElementById( "song-" + playerState.playlist.songs[playerState.currentSongIdx].yt_id, ); @@ -265,7 +263,7 @@ function shuffler(state) { state.playlist.songs.push(...extraSongs); __shuffleArray(state.playlist.songs); let sIdx = 0; - if (!!audioPlayerEl.src) { + if (!!audioPlayerEl.childNodes.length) { sIdx = state.playlist.songs.findIndex((s) => s.yt_id === songYtId); if (sIdx !== -1) { [state.playlist.songs[sIdx], state.playlist.songs[0]] = [ @@ -280,11 +278,9 @@ function shuffler(state) { const __toggleShuffle = () => { state.shuffled = !state.shuffled; if (state.shuffled) { + const src = audioPlayerEl.childNodes.item(0); shuffle( - audioPlayerEl.src.substring( - audioPlayerEl.src.lastIndexOf("/") + 1, - audioPlayerEl.src.length - 4, - ), + src.src.substring(src.src.lastIndexOf("/") + 1, src.src.length - 4), ); } else { const tmp = state.playlist.songs.sort((si, sj) => si.order - sj.order); @@ -298,14 +294,12 @@ function shuffler(state) { if (tmp[tmp.length - 1].yt_id !== tmp[tmp.length - 2]) { state.playlist.songs.push(tmp[tmp.length - 1]); } - if (!!audioPlayerEl.src) { + if (!!src) { + console.log("src", src.src); state.currentSongIdx = state.playlist.songs.findIndex( (s) => s.yt_id === - audioPlayerEl.src.substring( - audioPlayerEl.src.lastIndexOf("/") + 1, - audioPlayerEl.src.length - 4, - ), + src.src.substring(src.src.lastIndexOf("/") + 1, src.src.length - 4), ); } } @@ -626,6 +620,7 @@ async function playSong(song) { } const src = document.createElement("source"); src.src = `${location.protocol}//${location.host}/muzikkx/${song.yt_id}.mp3`; + src.target = "audio/mpeg"; audioPlayerEl.appendChild(src); // song's details setting, yada yada From 9beff28d98742e0e8295045a124b94c8e95439d3 Mon Sep 17 00:00:00 2001 From: Baraa Al-Masri Date: Thu, 4 Jul 2024 23:18:26 +0300 Subject: [PATCH 2/6] fix(player): add initial mute to trick webkit --- app/static/js/player.js | 1 + app/views/components/player/player.templ | 1 + 2 files changed, 2 insertions(+) diff --git a/app/static/js/player.js b/app/static/js/player.js index c7dee08..5808a56 100644 --- a/app/static/js/player.js +++ b/app/static/js/player.js @@ -185,6 +185,7 @@ function setLoading(loading, fallback) { */ function playPauser(audioEl) { const __play = () => { + audioEl.muted = null; audioEl.play(); const songEl = document.getElementById( "song-" + playerState.playlist.songs[playerState.currentSongIdx].yt_id, diff --git a/app/views/components/player/player.templ b/app/views/components/player/player.templ index cf4c0d1..35bb14f 100644 --- a/app/views/components/player/player.templ +++ b/app/views/components/player/player.templ @@ -36,6 +36,7 @@ templ PlayerSticky() { id="audio-player" controls preload="none" + muted > ///