const circle = document.querySelector('.progress-ring__circle');
const radius = circle.r.baseVal.value;
const circumference = Math.PI * radius;
circle.style.strokeDasharray = `${circumference} ${circumference}`;
circle.style.strokeDashoffset = circumference;
console.log(circumference);
function setOffset(percent) {
let offset = circumference - percent / 100 * circumference;
circle.style.strokeDashoffset = offset;
}
let songs = ["audio/song1.mp3", "audio/song2.mp3", "audio/song3.mp3"];
const fillBar = document.getElementById('fillBar'),
songTitle = document.getElementById('songTitle'),
handlePoint = document.getElementById('handle');
const pauseIcon = document.querySelector('.songStatus__pause'),
playIcon = document.querySelector('.songStatus__play');
let song = new Audio();
let currentSong = 0;
window.onload = function() {
song.src = songs[currentSong];
songTitle.textContent = songs[currentSong];
}
function playSong() {
song.src = songs[currentSong];
songTitle.textContent = songs[currentSong];
song.play();
}
function playOrPauseButton() {
currentVolume = song.volume;
if (song.paused) {
song.play();
console.log('Yahoo!');
let timerId = setTimeout(function tick() {
if (currentVolume >= 1) {
pauseIcon.classList.remove('hidden');
playIcon.classList.add('hidden');
} else {
currentVolume += 0.01;
console.log(currentVolume.toFixed(2));
song.volume = currentVolume.toFixed(2);
timerId = setTimeout(tick, 3);
}
}, 3);
} else {
let timerId = setTimeout(function tick() {
if (currentVolume <= 0) {
pauseIcon.classList.add('hidden');
playIcon.classList.remove('hidden');
song.pause();
currentVolume = 1;
} else {
currentVolume -= 0.01;
console.log(currentVolume.toFixed(2));
song.volume = currentVolume.toFixed(2);
timerId = setTimeout(tick, 3);
}
}, 3);
}
}
song.addEventListener('timeupdate', function() {
let position = song.currentTime / song.duration;
setOffset(position * 100);
handlePoint.style.transform = ' rotate(' + '-' + position * 180 + 'deg)' + ' translateY(50%) ';
if (song.currentTime == song.duration) {
playNextSong();
}
});
song.addEventListener('volumechange', () => {
});
function playNextSong() {
currentSong++;
if (currentSong > songs.length - 1) {
currentSong = 0;
}
playSong();
playIcon.classList.add('hidden');
pauseIcon.classList.remove('hidden');
}
function playPreviousSong() {
currentSong--;
if (currentSong < 0) {
currentSong = songs.length - 1;
}
playSong();
playIcon.classList.add('hidden');
pauseIcon.classList.remove('hidden');
}
function audioRewind() {
let currentRadius = (radius + 10)/100,
audioCurrentPos = event.offsetX;
song.currentTime = song.duration * (audioCurrentPos/circumference*currentRadius);
console.log(audioCurrentPos/circumference*currentRadius);
if ((audioCurrentPos/circumference*currentRadius) < 0.05) {
song.currentTime = 0;
}
}
const mm = require('node_modules/music-metadata');
async function parseFiles(audioFile) {
const metadata = await mm.parseFile(audioFile);
return metadata.trackInfo;
}
console.log(parseFiles(song));
let songs = ["audio/song1.mp3", "audio/song2.mp3", "audio/song3.mp3"];
const pauseIcon = document.querySelector('.songStatus__pause'),
playIcon = document.querySelector('.songStatus__play');
let song = new Audio();
let currentSong = 0;
window.onload = function() {
song.src = songs[currentSong];
songTitle.textContent = songs[currentSong];
}
function playSong() {
song.src = songs[currentSong];
songTitle.textContent = songs[currentSong];
song.play();
}
const mm = require('node_modules/music-metadata');
async function parseFiles(audioFile) {
const metadata = await mm.parseFile(audioFile);
return metadata.trackInfo;
}
console.log(parseFiles(song));