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6B,KACIE,GAAoBE,IACtBvB,IAKJ,SAASwB,EAAYC,GACnB,IAAMC,EAAanE,KAAKoE,YAElBC,EADaH,EAAGI,QACeH,EACrC9C,EAAKsC,YAAcU,EAAkBhD,EAAKM,SA/F5CK,EAASf,EAAMc,IAmGfF,EAAKS,iBAAiB,QAASG,GAG/BpB,EAAKiB,iBAAiB,OAAQc,GAC9B/B,EAAKiB,iBAAiB,QAASc,GAC/B/B,EAAKiB,iBAAiB,aAAckB,GACpCnC,EAAKiB,iBAAiB,QAASyB,EAAaQ,KAAK,MAAM,IAGvD3C,EAAKU,iBAAiB,QAASuB,GAG/B/B,EAAKQ,iBAAiB,QAASyB,EAAaQ,KAAK,MAAM,IAGvD/C,EAAkBc,iBAAiB,QAAS2B,IClJ9C3B,iBAAiB,oBAAoB,WACnC,IAAIkC,EAAgBjE,SAASkE,iBAAiB,6BAC9CC,OAAOC,OAAOH,GAAeI,KAAI,SAACC,GAChC,IAAIC,EAAcvE,SAASwE,eAAeF,EAAaG,IAE/CC,EAAoBC,KAAKC,MAAML,EAAYM,QAAQC,WAAnDJ,gBAERK,EAAU,IAAMT,EAAaG,GAAIC,S","sources":["webpack://mp3-player-block/webpack/bootstrap","webpack://mp3-player-block/webpack/runtime/global","webpack://mp3-player-block/webpack/runtime/publicPath","webpack://mp3-player-block/./assets/images/cover1.jpg","webpack://mp3-player-block/./assets/js/script.js","webpack://mp3-player-block/./src/script.js"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","__webpack_require__.g = (function() {\n\tif (typeof globalThis === 'object') return globalThis;\n\ttry {\n\t\treturn this || new Function('return this')();\n\t} catch (e) {\n\t\tif (typeof window === 'object') return window;\n\t}\n})();","var scriptUrl;\nif (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + \"\";\nvar document = __webpack_require__.g.document;\nif (!scriptUrl && document) {\n\tif (document.currentScript)\n\t\tscriptUrl = document.currentScript.src\n\tif (!scriptUrl) {\n\t\tvar scripts = document.getElementsByTagName(\"script\");\n\t\tif(scripts.length) scriptUrl = scripts[scripts.length - 1].src\n\t}\n}\n// When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration\n// or pass an empty string (\"\") and set the __webpack_public_path__ variable from your code to use your own logic.\nif (!scriptUrl) throw new Error(\"Automatic publicPath is not supported in this browser\");\nscriptUrl = scriptUrl.replace(/#.*$/, \"\").replace(/\\?.*$/, \"\").replace(/\\/[^\\/]+$/, \"/\");\n__webpack_require__.p = scriptUrl;","export default __webpack_public_path__ + \"assets/images/cover1.jpg\";","import CoverImage from \"../images/cover1.jpg\";\r\n\r\nconst MP3Player = (selector, songs = []) => {\r\n const element =\r\n typeof selector == \"string\" ? document.querySelector(selector) : selector;\r\n\r\n // console.log(songs);\r\n\r\n const cover = element.querySelector(\"#cover\");\r\n const disc = element.querySelector(\"#disc\");\r\n const title = element.querySelector(\"#title\");\r\n const artist = element.querySelector(\"#artist\");\r\n const progressContainer = element.querySelector(\"#progress-container\");\r\n const progress = element.querySelector(\"#progress\");\r\n const timer = element.querySelector(\"#timer\");\r\n const duration = element.querySelector(\"#duration\");\r\n const prev = element.querySelector(\"#prev\");\r\n const play = element.querySelector(\"#play\");\r\n const next = element.querySelector(\"#next\");\r\n let songIndex = 0;\r\n\r\n // Load song initially\r\n\r\n // Load the given song\r\n const loadSong = (song) => {\r\n cover.src = song.cover?.url || CoverImage;\r\n disc.src = song.audio?.url;\r\n title.textContent = song.title;\r\n artist.textContent = song.artist;\r\n // duration.textContent = song.duration;\r\n disc.addEventListener(\"loadedmetadata\", function () {\r\n duration.innerHTML = toHHMMSS(disc.duration);\r\n });\r\n };\r\n\r\n loadSong(songs[songIndex]);\r\n\r\n // Toggle play and pause\r\n function playPauseMedia() {\r\n if (disc.paused) {\r\n disc.play();\r\n } else {\r\n disc.pause();\r\n }\r\n }\r\n\r\n function toHHMMSS(time) {\r\n var sec_num = parseInt(time, 10); // don't forget the second param\r\n var hours = Math.floor(sec_num / 3600);\r\n var minutes = Math.floor((sec_num - hours * 3600) / 60);\r\n var seconds = sec_num - hours * 3600 - minutes * 60;\r\n\r\n if (hours < 10) {\r\n hours = \"0\" + hours;\r\n }\r\n if (minutes < 10) {\r\n minutes = \"0\" + minutes;\r\n }\r\n if (seconds < 10) {\r\n seconds = \"0\" + seconds;\r\n }\r\n return minutes + \":\" + seconds;\r\n }\r\n\r\n // Update icon\r\n function updatePlayPauseIcon() {\r\n if (disc.paused) {\r\n play.classList.remove(\"pauseBtn\");\r\n play.classList.add(\"playBtn\");\r\n } else {\r\n play.classList.remove(\"playBtn\");\r\n play.classList.add(\"pauseBtn\");\r\n }\r\n }\r\n\r\n // Update progress bar\r\n function updateProgress() {\r\n progress.style.width = (disc.currentTime / disc.duration) * 100 + \"%\";\r\n\r\n let minutes = Math.floor(disc.currentTime / 60);\r\n let seconds = Math.floor(disc.currentTime % 60);\r\n if (seconds < 10) {\r\n seconds = \"0\" + seconds;\r\n }\r\n timer.textContent = `${minutes}:${seconds}`;\r\n }\r\n\r\n // Reset the progress\r\n function resetProgress() {\r\n progress.style.width = 0 + \"%\";\r\n timer.textContent = \"0:00\";\r\n }\r\n\r\n // Go to previous song\r\n function gotoPreviousSong() {\r\n if (songIndex === 0) {\r\n songIndex = songs.length - 1;\r\n } else {\r\n songIndex = songIndex - 1;\r\n }\r\n\r\n const isDiscPlayingNow = !disc.paused;\r\n loadSong(songs[songIndex]);\r\n resetProgress();\r\n if (isDiscPlayingNow) {\r\n playPauseMedia();\r\n }\r\n }\r\n\r\n // Go to next song\r\n function gotoNextSong(playImmediately) {\r\n if (songIndex === songs.length - 1) {\r\n songIndex = 0;\r\n } else {\r\n songIndex = songIndex + 1;\r\n }\r\n\r\n const isDiscPlayingNow = !disc.paused;\r\n loadSong(songs[songIndex]);\r\n resetProgress();\r\n if (isDiscPlayingNow || playImmediately) {\r\n playPauseMedia();\r\n }\r\n }\r\n\r\n // Change song progress when clicked on progress bar\r\n function setProgress(ev) {\r\n const totalWidth = this.clientWidth;\r\n const clickWidth = ev.offsetX;\r\n const clickWidthRatio = clickWidth / totalWidth;\r\n disc.currentTime = clickWidthRatio * disc.duration;\r\n }\r\n\r\n // Play/Pause when play button clicked\r\n play.addEventListener(\"click\", playPauseMedia);\r\n\r\n // Various events on disc\r\n disc.addEventListener(\"play\", updatePlayPauseIcon);\r\n disc.addEventListener(\"pause\", updatePlayPauseIcon);\r\n disc.addEventListener(\"timeupdate\", updateProgress);\r\n disc.addEventListener(\"ended\", gotoNextSong.bind(null, true));\r\n\r\n // Go to next song when next button clicked\r\n prev.addEventListener(\"click\", gotoPreviousSong);\r\n\r\n // Go to previous song when previous button clicked\r\n next.addEventListener(\"click\", gotoNextSong.bind(null, false));\r\n\r\n // Move to different place in the song\r\n progressContainer.addEventListener(\"click\", setProgress);\r\n};\r\n\r\nexport default MP3Player;\r\n// export MP3Player\r\n","import \"./style.scss\";\r\nimport MP3Player from \"../assets/js/script\";\r\n\r\naddEventListener(\"DOMContentLoaded\", function () {\r\n let bmpbSelectors = document.querySelectorAll(\".wp-block-bpmp-mp3-player\");\r\n Object.values(bmpbSelectors).map((bmpbSelector) => {\r\n let mp3playerEl = document.getElementById(bmpbSelector.id);\r\n\r\n const { audioProperties } = JSON.parse(mp3playerEl.dataset.mp3player);\r\n\r\n MP3Player(\"#\" + bmpbSelector.id, audioProperties);\r\n });\r\n});\r\n"],"names":["__webpack_require__","g","globalThis","this","Function","e","window","scriptUrl","importScripts","location","document","currentScript","src","scripts","getElementsByTagName","length","Error","replace","p","selector","songs","element","querySelector","cover","disc","title","artist","progressContainer","progress","timer","duration","prev","play","next","songIndex","loadSong","song","url","CoverImage","audio","textContent","addEventListener","innerHTML","toHHMMSS","playPauseMedia","paused","pause","time","sec_num","parseInt","hours","Math","floor","minutes","seconds","updatePlayPauseIcon","classList","remove","add","updateProgress","style","width","currentTime","resetProgress","gotoPreviousSong","isDiscPlayingNow","gotoNextSong","playImmediately","setProgress","ev","totalWidth","clientWidth","clickWidthRatio","offsetX","bind","bmpbSelectors","querySelectorAll","Object","values","map","bmpbSelector","mp3playerEl","getElementById","id","audioProperties","JSON","parse","dataset","mp3player","MP3Player"],"sourceRoot":""}