Style & Control Changes
* Changes Control labels styles in initial popup * Changes key bindings * x - Toggle Play/Pause * a - Play previous (TODO) * d - Play Next (TODO) * w - Volume Up * s - Volume Down * Adds Swipe Up & Down * Volume Up & Down
This commit is contained in:
5
hg.css
5
hg.css
@@ -246,3 +246,8 @@ dialog::backdrop {
|
|||||||
#file-upload {
|
#file-upload {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.controls {
|
||||||
|
font-style: italic;
|
||||||
|
font-size: larger;
|
||||||
|
}
|
||||||
@@ -18,7 +18,9 @@
|
|||||||
<div class="modal-container">
|
<div class="modal-container">
|
||||||
<h3 class="text-center">Welcome to Retrowave Player</h3>
|
<h3 class="text-center">Welcome to Retrowave Player</h3>
|
||||||
<p class="mt-5">Here are the controls:</p>
|
<p class="mt-5">Here are the controls:</p>
|
||||||
<h4 class="mt-5">Play/Pause - Space/Click/Touch</h4>
|
<h4 class="mt-5">Play/Pause <span class="controls">x or Click or Touch</span></h4>
|
||||||
|
<h4 class="mt-5">Volume Up <span class="controls">w or Swipe Up</span></h4>
|
||||||
|
<h4 class="mt-5">Volume Down <span class="controls">s or Swipe Down</span></h4>
|
||||||
<p class="mt-5">(You can download the music history of your current browser by clicking the history link on the player)</p>
|
<p class="mt-5">(You can download the music history of your current browser by clicking the history link on the player)</p>
|
||||||
<button class="modal-close modal-exit" id="initButton">X</button>
|
<button class="modal-close modal-exit" id="initButton">X</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
66
player.js
66
player.js
@@ -9,6 +9,7 @@
|
|||||||
const modalEl = document.getElementById("intro-modal");
|
const modalEl = document.getElementById("intro-modal");
|
||||||
const uploadInfoEl = document.getElementById("upload-info");
|
const uploadInfoEl = document.getElementById("upload-info");
|
||||||
const fileUploadEl = document.getElementById("file-upload");
|
const fileUploadEl = document.getElementById("file-upload");
|
||||||
|
let volume = 1;
|
||||||
openDialog();
|
openDialog();
|
||||||
getMusic();
|
getMusic();
|
||||||
listenUploadFileChange();
|
listenUploadFileChange();
|
||||||
@@ -16,13 +17,7 @@
|
|||||||
coverArtEl.addEventListener("click", (event) => {
|
coverArtEl.addEventListener("click", (event) => {
|
||||||
const isNoPause = event.target.classList.contains("no-pause");
|
const isNoPause = event.target.classList.contains("no-pause");
|
||||||
if (howlerInstance && !isNoPause) {
|
if (howlerInstance && !isNoPause) {
|
||||||
isPlaying = !isPlaying;
|
togglePlay();
|
||||||
|
|
||||||
if (isPlaying) {
|
|
||||||
howlerInstance.play();
|
|
||||||
} else {
|
|
||||||
howlerInstance.pause();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -37,11 +32,9 @@
|
|||||||
function listenUploadFileChange() {
|
function listenUploadFileChange() {
|
||||||
fileUploadEl.onchange = function () {
|
fileUploadEl.onchange = function () {
|
||||||
const selectedFile = fileUploadEl.files[0];
|
const selectedFile = fileUploadEl.files[0];
|
||||||
console.log(selectedFile);
|
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.readAsText(selectedFile, "UTF-8");
|
reader.readAsText(selectedFile, "UTF-8");
|
||||||
reader.onload = function (event) {
|
reader.onload = function (event) {
|
||||||
console.log(event.target.result);
|
|
||||||
try {
|
try {
|
||||||
const uploadedPlaylist = JSON.parse(event.target.result);
|
const uploadedPlaylist = JSON.parse(event.target.result);
|
||||||
localStorage.setItem("retrowave-history", event.target.result);
|
localStorage.setItem("retrowave-history", event.target.result);
|
||||||
@@ -65,25 +58,36 @@
|
|||||||
document.addEventListener("keyup", (event) => {
|
document.addEventListener("keyup", (event) => {
|
||||||
const { key } = event;
|
const { key } = event;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "Space":
|
case "x":
|
||||||
|
togglePlay();
|
||||||
break;
|
break;
|
||||||
case "ArrowLeft":
|
case "a":
|
||||||
break;
|
break;
|
||||||
case "ArrowRight":
|
case "d":
|
||||||
|
break;
|
||||||
|
case "w":
|
||||||
|
volumeUp();
|
||||||
|
break;
|
||||||
|
case "s":
|
||||||
|
volumeDown();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let touchstartX = 0;
|
let touchstartX = 0;
|
||||||
let touchendX = 0;
|
let touchendX = 0;
|
||||||
|
let touchstartY = 0;
|
||||||
|
let touchendY = 0;
|
||||||
const musixPlayerEl = document.getElementsByClassName("music-player")[0];
|
const musixPlayerEl = document.getElementsByClassName("music-player")[0];
|
||||||
if (musixPlayerEl) {
|
if (musixPlayerEl) {
|
||||||
musixPlayerEl.addEventListener("touchstart", (e) => {
|
musixPlayerEl.addEventListener("touchstart", (e) => {
|
||||||
touchstartX = e.changedTouches[0].screenX;
|
touchstartX = e.changedTouches[0].screenX;
|
||||||
|
touchstartY = e.changedTouches[0].screenY;
|
||||||
});
|
});
|
||||||
|
|
||||||
musixPlayerEl.addEventListener("touchend", (e) => {
|
musixPlayerEl.addEventListener("touchend", (e) => {
|
||||||
touchendX = e.changedTouches[0].screenX;
|
touchendX = e.changedTouches[0].screenX;
|
||||||
|
touchendY = e.changedTouches[0].screenY;
|
||||||
checkDirection();
|
checkDirection();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -95,6 +99,13 @@
|
|||||||
if (touchendX > touchstartX) {
|
if (touchendX > touchstartX) {
|
||||||
// Swipe Right
|
// Swipe Right
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (touchendY < touchstartY) {
|
||||||
|
volumeUp();
|
||||||
|
}
|
||||||
|
if (touchendY > touchstartY) {
|
||||||
|
volumeDown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openDialog() {
|
function openDialog() {
|
||||||
@@ -130,6 +141,7 @@
|
|||||||
playMusic();
|
playMusic();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
setVolume();
|
||||||
isPlaying = true;
|
isPlaying = true;
|
||||||
|
|
||||||
updateInfo(currentTrack);
|
updateInfo(currentTrack);
|
||||||
@@ -138,6 +150,35 @@
|
|||||||
howlerInstance.play();
|
howlerInstance.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function volumeDown() {
|
||||||
|
console.log(volume);
|
||||||
|
if(volume>0.1) {
|
||||||
|
volume -= 0.1;
|
||||||
|
}
|
||||||
|
setVolume();
|
||||||
|
}
|
||||||
|
|
||||||
|
function volumeUp() {
|
||||||
|
if(volume<1) {
|
||||||
|
volume += 0.1;
|
||||||
|
}
|
||||||
|
setVolume();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setVolume() {
|
||||||
|
howlerInstance.volume(volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
function togglePlay() {
|
||||||
|
isPlaying = !isPlaying;
|
||||||
|
|
||||||
|
if (isPlaying) {
|
||||||
|
howlerInstance.play();
|
||||||
|
} else {
|
||||||
|
howlerInstance.pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function updateInfo(trackDetails) {
|
function updateInfo(trackDetails) {
|
||||||
titleEl.innerText = trackDetails.title;
|
titleEl.innerText = trackDetails.title;
|
||||||
coverArtEl.style.backgroundImage = `url("${retroWaveRu}${trackDetails.artworkUrl}")`;
|
coverArtEl.style.backgroundImage = `url("${retroWaveRu}${trackDetails.artworkUrl}")`;
|
||||||
@@ -146,7 +187,6 @@
|
|||||||
function getHistory() {
|
function getHistory() {
|
||||||
let localHistoryStore = localStorage.getItem("retrowave-history") || "[]";
|
let localHistoryStore = localStorage.getItem("retrowave-history") || "[]";
|
||||||
let historyArray = JSON.parse(localHistoryStore);
|
let historyArray = JSON.parse(localHistoryStore);
|
||||||
console.log(historyArray);
|
|
||||||
return historyArray;
|
return historyArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user