-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
542ab9f
commit cdf3a91
Showing
12 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.2/css/all.min.css" | ||
/> | ||
<link rel="stylesheet" href="style.css" /> | ||
<title>Wenura Ravindu</title> | ||
</head> | ||
<body> | ||
<h1>Music Player By Wenura</h1> | ||
|
||
<div class="music-container" id="music-container"> | ||
<div class="music-info"> | ||
<h4 id="title"></h4> | ||
<div class="progress-container" id="progress-container"> | ||
<div class="progress" id="progress"></div> | ||
</div> | ||
</div> | ||
|
||
<audio src="music/Viramayak.mp3" id="audio"></audio> | ||
|
||
<div class="img-container"> | ||
<img src="images/Viramayak.jpg" alt="music-cover" id="cover"> <img/> | ||
</div> | ||
<div class="navigation"> | ||
<button id="prev" class="action-btn"> | ||
<i class="fas fa-backward"></i> | ||
</button> | ||
<button id="play" class="action-btn action-btn-big"> | ||
<i class="fas fa-play"></i> | ||
</button> | ||
<button id="next" class="action-btn"> | ||
<i class="fas fa-forward"></i> | ||
</button> | ||
</div> | ||
</div> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
</html> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Music Player | ||
|
||
Create beautiful UI to play music stored in the "music folder" using the HTML5 audio API | ||
|
||
## Project Specifications | ||
|
||
- Create UI for music player including spinning image and song detail popup | ||
- Add play and pause functionality | ||
- Switch songs | ||
- Progress bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
const musicContainer = document.getElementById('music-container'); | ||
const playBtn = document.getElementById('play'); | ||
const prevBtn = document.getElementById('prev'); | ||
const nextBtn = document.getElementById('next'); | ||
|
||
const audio = document.getElementById('audio'); | ||
const progress = document.getElementById('progress'); | ||
const progressContainer = document.getElementById('progress-container'); | ||
const title = document.getElementById('title'); | ||
const cover = document.getElementById('cover'); | ||
const currTime = document.querySelector('#currTime'); | ||
const durTime = document.querySelector('#durTime'); | ||
|
||
// Song titles | ||
const songs = ['Viramayak' , 'Ma Nubata', 'Sulage Pavi', 'Pem Thalam']; | ||
|
||
// Keep track of song | ||
let songIndex = 1; | ||
|
||
// Initially load song details into DOM | ||
loadSong(songs[songIndex]); | ||
|
||
// Update song details | ||
function loadSong(song) { | ||
title.innerText = song; | ||
audio.src = `music/${song}.mp3`; | ||
cover.src = `images/${song}.jpg`; | ||
} | ||
|
||
// Play song | ||
function playSong() { | ||
musicContainer.classList.add('play'); | ||
playBtn.querySelector('i.fas').classList.remove('fa-play'); | ||
playBtn.querySelector('i.fas').classList.add('fa-pause'); | ||
|
||
audio.play(); | ||
} | ||
|
||
// Pause song | ||
function pauseSong() { | ||
musicContainer.classList.remove('play'); | ||
playBtn.querySelector('i.fas').classList.add('fa-play'); | ||
playBtn.querySelector('i.fas').classList.remove('fa-pause'); | ||
|
||
audio.pause(); | ||
} | ||
|
||
// Previous song | ||
function prevSong() { | ||
songIndex--; | ||
|
||
if (songIndex < 0) { | ||
songIndex = songs.length - 1; | ||
} | ||
|
||
loadSong(songs[songIndex]); | ||
|
||
playSong(); | ||
} | ||
|
||
// Next song | ||
function nextSong() { | ||
songIndex++; | ||
|
||
if (songIndex > songs.length - 1) { | ||
songIndex = 0; | ||
} | ||
|
||
loadSong(songs[songIndex]); | ||
|
||
playSong(); | ||
} | ||
|
||
// Update progress bar | ||
function updateProgress(e) { | ||
const { duration, currentTime } = e.srcElement; | ||
const progressPercent = (currentTime / duration) * 100; | ||
progress.style.width = `${progressPercent}%`; | ||
} | ||
|
||
// Set progress bar | ||
function setProgress(e) { | ||
const width = this.clientWidth; | ||
const clickX = e.offsetX; | ||
const duration = audio.duration; | ||
|
||
audio.currentTime = (clickX / width) * duration; | ||
} | ||
|
||
//get duration & currentTime for Time of song | ||
function DurTime (e) { | ||
const {duration,currentTime} = e.srcElement; | ||
var sec; | ||
var sec_d; | ||
|
||
// define minutes currentTime | ||
let min = (currentTime==null)? 0: | ||
Math.floor(currentTime/60); | ||
min = min <10 ? '0'+min:min; | ||
|
||
// define seconds currentTime | ||
function get_sec (x) { | ||
if(Math.floor(x) >= 60){ | ||
|
||
for (var i = 1; i<=60; i++){ | ||
if(Math.floor(x)>=(60*i) && Math.floor(x)<(60*(i+1))) { | ||
sec = Math.floor(x) - (60*i); | ||
sec = sec <10 ? '0'+sec:sec; | ||
} | ||
} | ||
}else{ | ||
sec = Math.floor(x); | ||
sec = sec <10 ? '0'+sec:sec; | ||
} | ||
} | ||
|
||
get_sec (currentTime,sec); | ||
|
||
// change currentTime DOM | ||
currTime.innerHTML = min +':'+ sec; | ||
|
||
// define minutes duration | ||
let min_d = (isNaN(duration) === true)? '0': | ||
Math.floor(duration/60); | ||
min_d = min_d <10 ? '0'+min_d:min_d; | ||
|
||
|
||
function get_sec_d (x) { | ||
if(Math.floor(x) >= 60){ | ||
|
||
for (var i = 1; i<=60; i++){ | ||
if(Math.floor(x)>=(60*i) && Math.floor(x)<(60*(i+1))) { | ||
sec_d = Math.floor(x) - (60*i); | ||
sec_d = sec_d <10 ? '0'+sec_d:sec_d; | ||
} | ||
} | ||
}else{ | ||
sec_d = (isNaN(duration) === true)? '0': | ||
Math.floor(x); | ||
sec_d = sec_d <10 ? '0'+sec_d:sec_d; | ||
} | ||
} | ||
|
||
// define seconds duration | ||
|
||
get_sec_d (duration); | ||
|
||
// change duration DOM | ||
durTime.innerHTML = min_d +':'+ sec_d; | ||
|
||
}; | ||
|
||
// Event listeners | ||
playBtn.addEventListener('click', () => { | ||
const isPlaying = musicContainer.classList.contains('play'); | ||
|
||
if (isPlaying) { | ||
pauseSong(); | ||
} else { | ||
playSong(); | ||
} | ||
}); | ||
|
||
// Change song | ||
prevBtn.addEventListener('click', prevSong); | ||
nextBtn.addEventListener('click', nextSong); | ||
|
||
// Time/song update | ||
audio.addEventListener('timeupdate', updateProgress); | ||
|
||
// Click on progress bar | ||
progressContainer.addEventListener('click', setProgress); | ||
|
||
// Song ends | ||
audio.addEventListener('ended', nextSong); | ||
|
||
// Time of song | ||
audio.addEventListener('timeupdate',DurTime); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
@import url('https://fonts.googleapis.com/css?family=Lato&display=swap'); | ||
|
||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
body { | ||
background-image: linear-gradient( | ||
0deg, | ||
rgba(247, 247, 247, 1) 23.8%, | ||
rgba(252, 221, 221, 1) 92% | ||
); | ||
height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-family: 'Lato', sans-serif; | ||
margin: 0; | ||
} | ||
|
||
.music-container { | ||
background-color: #fff; | ||
border-radius: 15px; | ||
box-shadow: 0 20px 20px 0 rgba(252, 169, 169, 0.6); | ||
display: flex; | ||
padding: 20px 30px; | ||
position: relative; | ||
margin: 100px 0; | ||
z-index: 10; | ||
} | ||
|
||
.img-container { | ||
position: relative; | ||
width: 110px; | ||
} | ||
|
||
.img-container::after { | ||
content: ''; | ||
background-color: #fff; | ||
border-radius: 50%; | ||
position: absolute; | ||
bottom: 100%; | ||
left: 50%; | ||
width: 20px; | ||
height: 20px; | ||
transform: translate(-50%, 50%); | ||
} | ||
|
||
.img-container img { | ||
border-radius: 50%; | ||
object-fit: cover; | ||
height: 110px; | ||
width: inherit; | ||
position: absolute; | ||
bottom: 0; | ||
left: 0; | ||
animation: rotate 3s linear infinite; | ||
|
||
animation-play-state: paused; | ||
} | ||
|
||
.music-container.play .img-container img { | ||
animation-play-state: running; | ||
} | ||
|
||
@keyframes rotate { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
|
||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
.navigation { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
z-index: 1; | ||
} | ||
|
||
.action-btn { | ||
background-color: #fff; | ||
border: 0; | ||
color: #dfdbdf; | ||
font-size: 20px; | ||
cursor: pointer; | ||
padding: 10px; | ||
margin: 0 20px; | ||
} | ||
|
||
.action-btn.action-btn-big { | ||
color: #cdc2d0; | ||
font-size: 30px; | ||
} | ||
|
||
.action-btn:focus { | ||
outline: 0; | ||
} | ||
|
||
.music-info { | ||
background-color: rgba(255, 255, 255, 0.5); | ||
border-radius: 15px 15px 0 0; | ||
position: absolute; | ||
top: 0; | ||
left: 20px; | ||
width: calc(100% - 40px); | ||
padding: 10px 10px 10px 150px; | ||
opacity: 0; | ||
transform: translateY(0%); | ||
transition: transform 0.3s ease-in, opacity 0.3s ease-in; | ||
z-index: 0; | ||
} | ||
|
||
.music-container.play .music-info { | ||
opacity: 1; | ||
transform: translateY(-100%); | ||
} | ||
|
||
.music-info h4 { | ||
margin: 0; | ||
} | ||
|
||
.progress-container { | ||
background: #fff; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
margin: 10px 0; | ||
height: 4px; | ||
width: 100%; | ||
} | ||
|
||
.progress { | ||
background-color: #fe8daa; | ||
border-radius: 5px; | ||
height: 100%; | ||
width: 0%; | ||
transition: width 0.1s linear; | ||
} |