Skip to content

Commit

Permalink
v2.0: Added Progress Bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Sas2k committed Dec 28, 2022
1 parent 1f86cb1 commit aff0f35
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 21 deletions.
57 changes: 36 additions & 21 deletions static/js/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
playState = false;
sound = document.getElementById('audio');
let audio = document.getElementById('audio');
let progress = document.getElementById('progress');
let stopper = document.getElementById('stopper');
let current = document.getElementById('current');
let duration = document.getElementById('duration');

function play(){
if(playState == false){
playState = true;
document.getElementById("stopper").classList.remove("fa-play");
document.getElementById("stopper").classList.add("fa-pause");

sound.play();
function play() {
if (audio.paused) {
audio.play();
stopper.classList.remove('fa-play');
stopper.classList.add('fa-pause');
} else {
playState = false;
document.getElementById("stopper").classList.remove("fa-pause");
document.getElementById("stopper").classList.add("fa-play");
audio.pause();
stopper.classList.remove('fa-pause');
stopper.classList.add('fa-play');
}
}

function updateProgress() {
progress.value = (audio.currentTime / audio.duration) * 100;
let min = Math.floor(audio.currentTime / 60);
let sec = Math.floor(audio.currentTime % 60);
if (sec < 10) {
sec = `0${sec}`;
}
current.innerHTML = `${min}:${sec}`;
let durationMin = Math.floor(audio.duration / 60);
let durationSec = Math.floor(audio.duration % 60);
if (durationSec < 10) {
durationSec = `0${durationSec}`;
}
duration.innerHTML = `${durationMin}:${durationSec}`;
}

sound.pause();
};
};
function setProgress() {
audio.currentTime = (progress.value * audio.duration) / 100;
}

sound.onended = function() {
playState = false;
document.getElementById("stopper").classList.remove("fa-pause");
document.getElementById("stopper").classList.add("fa-play");
sound.currentTime = 0;
}
audio.addEventListener('timeupdate', updateProgress);
progress.addEventListener('click', setProgress);
13 changes: 13 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ <h1 class="title">{{ Title }}</h1>
<p class="subtitle">Track: #{{ TrackNum }}</p>
</div>
</div>
<div class="columns">
<div class="column">
<progress id="progress" class="progress is-primary" value="0" max="100">0%</progress>
<div class="columns">
<div class="column">
<p id="current">0:00</p>
</div>
<div class="column">
<p id="duration">0:00</p>
</div>
</div>
</div>
</div>
</div>
<div class="block">
<div class="buttons">
Expand Down
13 changes: 13 additions & 0 deletions templates/song.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ <h1 class="title">{{ Title }}</h1>
<p class="subtitle">Track: #{{TrackNum}}</p>
</div>
</div>
<div class="columns">
<div class="column">
<progress id="progress" class="progress is-primary" value="0" max="100">0%</progress>
<div class="columns">
<div class="column">
<p id="current">0:00</p>
</div>
<div class="column">
<p id="duration">0:00</p>
</div>
</div>
</div>
</div>
</div>
<div class="block">
<div class="buttons">
Expand Down

1 comment on commit aff0f35

@vercel
Copy link

@vercel vercel bot commented on aff0f35 Dec 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

songtrack – ./

songtrack.vercel.app
songtrack-git-main-sas2k.vercel.app
songtrack-sas2k.vercel.app

Please sign in to comment.