riddhiman commited on
Commit
0181a40
·
verified ·
1 Parent(s): 848bf07

Update public/script.js

Browse files
Files changed (1) hide show
  1. public/script.js +24 -0
public/script.js CHANGED
@@ -187,6 +187,30 @@ function setupCustomAudioPlayer() {
187
 
188
  // Initial volume (100%)
189
  audio.volume = 1.0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  }
191
 
192
  function playMusic(fileName) {
 
187
 
188
  // Initial volume (100%)
189
  audio.volume = 1.0;
190
+
191
+ audio.addEventListener('timeupdate', function() {
192
+ updateProgress();
193
+ });
194
+
195
+ // When audio metadata is loaded, update duration
196
+ audio.addEventListener('loadedmetadata', function() {
197
+ document.getElementById('duration').textContent = formatTime(audio.duration);
198
+ });
199
+ }
200
+
201
+ function updateProgress() {
202
+ const progress = document.getElementById('progress-bar');
203
+ progress.value = (audio.currentTime / audio.duration) * 100;
204
+
205
+ document.getElementById('current-time').textContent = formatTime(audio.currentTime);
206
+ }
207
+
208
+ function formatTime(seconds) {
209
+ let minutes = Math.floor(seconds / 60);
210
+ minutes = (minutes >= 10) ? minutes : "0" + minutes;
211
+ seconds = Math.floor(seconds % 60);
212
+ seconds = (seconds >= 10) ? seconds : "0" + seconds;
213
+ return minutes + ":" + seconds;
214
  }
215
 
216
  function playMusic(fileName) {