Untitled
unknown
javascript
2 years ago
1.7 kB
10
Indexable
function seekTo() { // Calculate the seek position by the // percentage of the seek slider // and get the relative duration to the track seekTo = curr_track.duration * (seek_slider.value / 100); // Set the current track position to the calculated seek position curr_track.currentTime = seekTo; } function setVolume() { // Set the volume according to the // percentage of the volume slider set curr_track.volume = volume_slider.value / 100; } function seekUpdate() { let seekPosition = 0; // Check if the current track duration is a legible number if (!isNaN(curr_track.duration)) { seekPosition = curr_track.currentTime * (100 / curr_track.duration); seek_slider.value = seekPosition; // Calculate the time left and the total duration let currentMinutes = Math.floor(curr_track.currentTime / 60); let currentSeconds = Math.floor(curr_track.currentTime - currentMinutes * 60); let durationMinutes = Math.floor(curr_track.duration / 60); let durationSeconds = Math.floor(curr_track.duration - durationMinutes * 60); // Add a zero to the single digit time values if (currentSeconds < 10) { currentSeconds = "0" + currentSeconds; } if (durationSeconds < 10) { durationSeconds = "0" + durationSeconds; } if (currentMinutes < 10) { currentMinutes = "0" + currentMinutes; } if (durationMinutes < 10) { durationMinutes = "0" + durationMinutes; } // Display the updated duration curr_time.textContent = currentMinutes + ":" + currentSeconds; total_duration.textContent = durationMinutes + ":" + durationSeconds; } } // Load the first track in the tracklist loadTrack(track_index);
Editor is loading...