diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..7bb2f2b Binary files /dev/null and b/logo.png differ diff --git a/playing.gif b/playing.gif new file mode 100644 index 0000000..e77bdb4 Binary files /dev/null and b/playing.gif differ diff --git a/script.js b/script.js new file mode 100644 index 0000000..8077c8e --- /dev/null +++ b/script.js @@ -0,0 +1,117 @@ +console.log("Welcome to Spotify"); + +// Initialize the Variables +let songIndex = 0; +let audioElement = new Audio('songs/1.mp3'); +let masterPlay = document.getElementById('masterPlay'); +let myProgressBar = document.getElementById('myProgressBar'); +let gif = document.getElementById('gif'); +let masterSongName = document.getElementById('masterSongName'); +let songItems = Array.from(document.getElementsByClassName('songItem')); + +let songs = [ + { songName: "Warriyo - Mortals [NCS Release]", filePath: "songs/1.mp3", coverPath: "covers/1.jpg" }, + { songName: "Cielo - Huma-Huma", filePath: "songs/2.mp3", coverPath: "covers/2.jpg" }, + { songName: "DEAF KEV - Invincible [NCS Release]-320k", filePath: "songs/3.mp3", coverPath: "covers/3.jpg" }, + { songName: "Different Heaven & EH!DE - My Heart [NCS Release]", filePath: "songs/4.mp3", coverPath: "covers/4.jpg" }, + { songName: "Janji-Heroes-Tonight-feat-Johnning-NCS-Release", filePath: "songs/5.mp3", coverPath: "covers/5.jpg" }, + { songName: "Rabba - Salam-e-Ishq", filePath: "songs/2.mp3", coverPath: "covers/6.jpg" }, + { songName: "Sakhiyaan - Salam-e-Ishq", filePath: "songs/2.mp3", coverPath: "covers/7.jpg" }, + { 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: "Zihal e Maskin- fav songs", filePath: "E:/Spotify Clone/songs/11.mp3", coverPath: "covers/11.jpg" }, + { + songName: "Har Har Shambhu Shiv Mahadev-(Pagal World.com)", + filePath: "E:/Spotify Clone/songs/12.mp3", coverPath: "covers/12.jpg" + }, + { songName: "Man Meri Jaan", filePath: "E:/Spotify Clone/songs/13.mp3", coverPath: "covers/13.jpg" }, + { songName: "Tu Hai To Mujhe Kuch Or Kya Chaiye", filePath: "E:/Spotify Clone/songs/14.mp3", coverPath: "covers/14.jpg" }, + +] + +songItems.forEach((element, i) => { + element.getElementsByTagName("img")[0].src = songs[i].coverPath; + element.getElementsByClassName("songName")[0].innerText = songs[i].songName; +}) + + +// Handle play/pause click +masterPlay.addEventListener('click', () => { + if (audioElement.paused || audioElement.currentTime <= 0) { + audioElement.play(); + masterPlay.classList.remove('fa-play-circle'); + masterPlay.classList.add('fa-pause-circle'); + gif.style.opacity = 1; + } + else { + audioElement.pause(); + masterPlay.classList.remove('fa-pause-circle'); + masterPlay.classList.add('fa-play-circle'); + gif.style.opacity = 0; + } +}) +// Listen to Events +audioElement.addEventListener('timeupdate', () => { + // Update Seekbar + progress = parseInt((audioElement.currentTime / audioElement.duration) * 100); + myProgressBar.value = progress; +}) + +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(); + songIndex = parseInt(e.target.id); + e.target.classList.remove('fa-play-circle'); + e.target.classList.add('fa-pause-circle'); + audioElement.src = `songs/${songIndex + 1}.mp3`; + masterSongName.innerText = songs[songIndex].songName; + audioElement.currentTime = 0; + audioElement.play(); + gif.style.opacity = 1; + 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'); +}) \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..0018fdf --- /dev/null +++ b/style.css @@ -0,0 +1,122 @@ +@import url('https://fonts.googleapis.com/css2?family=Ubuntu&display=swap'); +@import url('https://fonts.googleapis.com/css2?family=Varela+Round&display=swap'); +body{ + background-color: antiquewhite; +} + +*{ + margin: 0; + padding: 0; +} + +nav{ + font-family: 'Ubuntu', sans-serif; +} + +nav ul{ + display: flex; + align-items: center; + list-style-type: none; + height: 65px; + background-color: black; + color: white; +} + +nav ul li{ + padding: 0 12px; +} +.brand img{ + width: 44px; + padding: 0 8px; +} + +.brand { + display: flex; + align-items: center; + font-weight: bolder; + font-size: 1.3rem; +} + +.container{ + min-height: 72vh; + background-color: black; + color: white; + font-family: 'Varela Round', sans-serif; + display: flex; + margin: 23px auto; + width: 70%; + border-radius: 12px; + padding: 34px; + background-image: url('bg.jpg'); +} + +.bottom{ + position: sticky; + bottom: 0; + height: 130px; + background-color: black; + color: white; + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; +} + +.icons{ + margin-top: 14px; +} +.icons i{ + cursor: pointer; +} + +#myProgressBar{ + width: 80vw; + cursor: pointer; +} + +.songItemContainer{ + margin-top: 74px; +} + +.songItem{ + height: 50px; + display: flex; + background-color: white; + + color: black; + margin: 12px 0; + justify-content: space-between; + align-items: center; + border-radius: 34px; +} + +.songItem img{ + width: 43px; + margin: 0 23px; + border-radius: 34px; +} + +.timestamp{ + margin: 0 23px; +} + +.timestamp i{ + cursor: pointer; +} + +.songInfo{ + position: absolute; + left: 10vw; + font-family: 'Varela Round', sans-serif; +} + +.songInfo img{ + opacity: 0; + transition: opacity 0.4s ease-in; +} + +@media only screen and (max-width: 1100px) { + body { + background-color: red; + } + } \ No newline at end of file