Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added covers/11.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 22 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Spotify</title>
<link rel="stylesheet" href="style.css">
</head>
<link rel="icon" href="logo.png" type="images/png">
</head>
<body>
<nav>
<ul>
<li class="brand"><img src="logo.png" alt="Spotify"> Spotify</li>
<li>Home</li>
<li>About</li>
<li>Profile</li>
</ul>
</nav>

Expand All @@ -23,52 +25,57 @@ <h1>Best of NCS - No Copyright Sounds</h1>
<div class="songItem">
<img alt="1">
<span class="songName">Let me Love You</span>
<span class="songlistplay"><span class="timestamp">05:34 <i id="0" class="far songItemPlay fa-play-circle"></i> </span></span>
<span class="songlistplay"><span class="timestamp">03:50 <i id="0" class="far songItemPlay fa-play-circle"></i> </span></span>
</div>
<div class="songItem">
<img alt="1">
<span class="songName">Let me Love You</span>
<span class="songlistplay"><span class="timestamp">05:34 <i id="1" class="far songItemPlay fa-play-circle"></i> </span></span>
<span class="songlistplay"><span class="timestamp">02:33 <i id="1" class="far songItemPlay fa-play-circle"></i> </span></span>
</div>
<div class="songItem">
<img alt="1">
<span class="songName">Let me Love You</span>
<span class="songlistplay"><span class="timestamp">05:34 <i id="2" class="far songItemPlay fa-play-circle"></i> </span></span>
<span class="songlistplay"><span class="timestamp">04:33 <i id="2" class="far songItemPlay fa-play-circle"></i> </span></span>
</div>
<div class="songItem">
<img alt="1">
<span class="songName">Let me Love You</span>
<span class="songlistplay"><span class="timestamp">05:34 <i id="3" class="far songItemPlay fa-play-circle"></i> </span></span>
<span class="songlistplay"><span class="timestamp">04:27 <i id="3" class="far songItemPlay fa-play-circle"></i> </span></span>
</div>
<div class="songItem">
<img alt="1">
<span class="songName">Let me Love You</span>
<span class="songlistplay"><span class="timestamp">05:34 <i id="4" class="far songItemPlay fa-play-circle"></i> </span></span>
<span class="songlistplay"><span class="timestamp">03:28 <i id="4" class="far songItemPlay fa-play-circle"></i> </span></span>
</div>
<div class="songItem">
<img alt="1">
<span class="songName">Let me Love You</span>
<span class="songlistplay"><span class="timestamp">05:34 <i id="5" class="far songItemPlay fa-play-circle"></i> </span></span>
<span class="songlistplay"><span class="timestamp">03:28 <i id="5" class="far songItemPlay fa-play-circle"></i> </span></span>
</div>
<div class="songItem">
<img alt="1">
<span class="songName">Let me Love You</span>
<span class="songlistplay"><span class="timestamp">05:34 <i id="6" class="far songItemPlay fa-play-circle"></i> </span></span>
<span class="songlistplay"><span class="timestamp">04:33 <i id="6" class="far songItemPlay fa-play-circle"></i> </span></span>
</div>
<div class="songItem">
<img alt="1">
<span class="songName">Let me Love You</span>
<span class="songlistplay"><span class="timestamp">05:34 <i id="7" class="far songItemPlay fa-play-circle"></i> </span></span>
<span class="songlistplay"><span class="timestamp">03:50 <i id="7" class="far songItemPlay fa-play-circle"></i> </span></span>
</div>
<div class="songItem">
<img alt="1">
<span class="songName">Let me Love You</span>
<span class="songlistplay"><span class="timestamp">05:34 <i id="8" class="far songItemPlay fa-play-circle"></i> </span></span>
<span class="songlistplay"><span class="timestamp">03:28 <i id="8" class="far songItemPlay fa-play-circle"></i> </span></span>
</div>
<div class="songItem">
<img alt="1">
<span class="songName">Let me Love You</span>
<span class="songlistplay"><span class="timestamp">05:34 <i id="9" class="far songItemPlay fa-play-circle"></i> </span></span>
<span class="songlistplay"><span class="timestamp">04:27 <i id="9" class="far songItemPlay fa-play-circle"></i> </span></span>
</div>
<div class="songItem">
<img alt="1">
<span class="songName">Let me Love You</span>
<span class="songlistplay"><span class="timestamp">00:16 <i id="10" class="far songItemPlay fa-play-circle"></i> </span></span>
</div>
</div>
</div>
Expand All @@ -82,9 +89,13 @@ <h1>Best of NCS - No Copyright Sounds</h1>
<i class="fas fa-3x fa-step-backward" id="previous"></i>
<i class="far fa-3x fa-play-circle" id="masterPlay"></i>
<i class="fas fa-3x fa-step-forward" id="next"></i>
<i class="fas fa-3x fa-sync" id="loop"></i>
<i class="fas fa-3x fa-volume-off" id="mute"></i>
</div>
<div class="songInfo">
<img src="playing.gif" width="42px" alt="" id="gif"> <span id="masterSongName">Warriyo - Mortals [NCS Release]</span>
<br>
<span class="songinfo"></span>
</div>
</div>
<script src="script.js"></script>
Expand Down
181 changes: 129 additions & 52 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ let masterPlay = document.getElementById('masterPlay');
let myProgressBar = document.getElementById('myProgressBar');
let gif = document.getElementById('gif');
let masterSongName = document.getElementById('masterSongName');
let isLooping = false;
let isMuted=false;
let songItems = Array.from(document.getElementsByClassName('songItem'));

let songs = [
Expand All @@ -20,47 +22,153 @@ let songs = [
{songName: "Bhula Dena - Salam-e-Ishq", filePath: "songs/2.mp3", coverPath: "covers/8.jpg"},
{songName: "Tumhari Kasam - Salam-e-Ishq", filePath: "songs/2.mp3", coverPath: "covers/9.jpg"},
{songName: "Na Jaana - Salam-e-Ishq", filePath: "songs/4.mp3", coverPath: "covers/10.jpg"},
{songName: "Neffex Best Of ME", filePath: "songs/11.mp3", coverPath: "covers/11.jpg"},
]

songItems.forEach((element, i)=>{
element.getElementsByTagName("img")[0].src = songs[i].coverPath;
element.getElementsByClassName("songName")[0].innerText = songs[i].songName;
//pupulate items with cover images and song names
function syncUI(){
songItems.forEach((element,i)=>{
console.log(element,i);
element.getElementsByTagName("img")[0].src = songs[i].coverPath;
element.getElementsByClassName("songName")[0].innerText = songs[i].songName;
// element.getElementsByClassName("timestamp")[0].innerText = formatTime(audioElement.duration);
})


}
syncUI();
// handle previous button click event
function previous(){
if(songIndex<=0){
songIndex=songs.length-1;
}
else{
songIndex-=1;
}
playSelectedSong();
}
//handle forward button click event
function forward(){
if(songIndex>=(songs.length-1)){
songIndex=0;
}
else{
songIndex+=1;
}
playSelectedSong();
}
// Handle play/pause click
masterPlay.addEventListener('click', ()=>{
if(audioElement.paused || audioElement.currentTime<=0){
function play(){
if(audioElement.paused||audioElement.currentTime<=0){
audioElement.play();
masterPlay.classList.remove('fa-play-circle');
masterPlay.classList.add('fa-pause-circle');
gif.style.opacity = 1;
masterPlay.classList.remove('fa-circle-play');
masterPlay.classList.add('fa-circle-pause');
gif.style.opacity=1;
}
else{
audioElement.pause();
masterPlay.classList.remove('fa-pause-circle');
masterPlay.classList.add('fa-play-circle');
gif.style.opacity = 0;
masterPlay.classList.remove('fa-circle-pause');
masterPlay.classList.add('fa-circle-play');
gif.style.opacity=0;
}
})
}
// function to play the selected song
function playSelectedSong() {
audioElement.src = songs[songIndex].filePath;
audioElement.currentTime = 0;
audioElement.play();
gif.style.opacity=1;
masterSongName.innerText = songs[songIndex].songName;
makeAllPlays();
masterPlay.classList.remove('fa-circle-play');
masterPlay.classList.add('fa-circle-pause');
}
//function to format time in minutes and seconds
function formatTime(seconds) {
let minutes = Math.floor(seconds / 60);
let remainingSeconds = Math.floor(seconds % 60);
return `${minutes}:${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`;
}
//for muting one song
function mute(){
if (!isMuted) {
audioElement.muted = true;
document.getElementById('mute').classList.remove('volume-off');
} else {
audioElement.muted = false;
document.getElementById('mute').classList.add('volume-high');
}
isMuted = !isMuted;
}
//for the looping one song
function loop(){
if (!isLooping) {
audioElement.loop = true;
// document.getElementById(gif.)
document.getElementById('loop').classList.add('fa-beat');
} else {
audioElement.loop = false;
document.getElementById('loop').classList.remove('fa-beat');
}
isLooping = !isLooping;
}
const makeAllPlays = ()=>{
Array.from(document.getElementsByClassName('songItemPlay')).forEach((element)=>{
element.classList.remove('fa-pause-circle');
element.classList.add('fa-play-circle');
})
}
//handle time update event
function updateTimestamp() {
const currentTimestamp = formatTime(audioElement.currentTime);
const totalTimestamp = formatTime(audioElement.duration);
document.querySelector('.songinfo').innerText = `${currentTimestamp} / ${totalTimestamp}`;
}
// Listen to Events

document.getElementById('mute').addEventListener('click', () => {
mute();
});
document.getElementById('previous').addEventListener('click',()=>{
previous();
})
document.getElementById('next').addEventListener('click',()=>{
forward();
})
document.getElementById('loop').addEventListener('click', () => {
loop();
});
masterPlay.addEventListener('click',()=>{
play();
})
// listning to keyboard
document.addEventListener('keydown',(Event)=>{
if(Event.code==="Space"){
play();
}
if(Event.code==="KeyM"){
mute();
}
if(Event.code==="ArrowUp"){
if (audioElement.volume < 1.0) {
audioElement.volume += 0.1; // You can adjust the increment as needed
}
}
if(Event.code==="ArrowDown"){
if (audioElement.volume > 0.0) {
audioElement.volume -= 0.1; // You can adjust the decrement as needed
}
}
});
audioElement.addEventListener('timeupdate', ()=>{
// Update Seekbar
progress = parseInt((audioElement.currentTime/audioElement.duration)* 100);
myProgressBar.value = progress;
updateTimestamp();
})

myProgressBar.addEventListener('change', ()=>{
audioElement.currentTime = myProgressBar.value * audioElement.duration/100;
})

const makeAllPlays = ()=>{
Array.from(document.getElementsByClassName('songItemPlay')).forEach((element)=>{
element.classList.remove('fa-pause-circle');
element.classList.add('fa-play-circle');
})
}

Array.from(document.getElementsByClassName('songItemPlay')).forEach((element)=>{
element.addEventListener('click', (e)=>{
makeAllPlays();
Expand All @@ -75,35 +183,4 @@ Array.from(document.getElementsByClassName('songItemPlay')).forEach((element)=>{
masterPlay.classList.remove('fa-play-circle');
masterPlay.classList.add('fa-pause-circle');
})
})

document.getElementById('next').addEventListener('click', ()=>{
if(songIndex>=9){
songIndex = 0
}
else{
songIndex += 1;
}
audioElement.src = `songs/${songIndex+1}.mp3`;
masterSongName.innerText = songs[songIndex].songName;
audioElement.currentTime = 0;
audioElement.play();
masterPlay.classList.remove('fa-play-circle');
masterPlay.classList.add('fa-pause-circle');

})

document.getElementById('previous').addEventListener('click', ()=>{
if(songIndex<=0){
songIndex = 0
}
else{
songIndex -= 1;
}
audioElement.src = `songs/${songIndex+1}.mp3`;
masterSongName.innerText = songs[songIndex].songName;
audioElement.currentTime = 0;
audioElement.play();
masterPlay.classList.remove('fa-play-circle');
masterPlay.classList.add('fa-pause-circle');
})
Binary file added songs/11.mp3
Binary file not shown.
11 changes: 11 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ nav ul li{

.icons{
margin-top: 14px;
display: flex;
justify-content: space-between;
align-items: center;
}
.icons i{
cursor: pointer;
Expand Down Expand Up @@ -109,6 +112,14 @@ nav ul li{
left: 10vw;
font-family: 'Varela Round', sans-serif;
}
#loop{
margin-left: 70%;
color: white;
}
#mute{
color: white;;
margin-left: 80%;
}

.songInfo img{
opacity: 0;
Expand Down