$(document).ready(function(){ const media = $('video'); const controls = $('.controls'); const play = $('.play'); const stop = $('.stop'); const rwd = $('.rwd'); const fwd = $('.fwd'); const timerWrapper = $('.timer'); const timer = $('.timer span'); const timerBar = $('.timer div'); media.removeAttribute('controls'); controls.css('visibility', 'visible'); play.addEventListener('click', playPauseMedia); stop.addEventListener('click', stopMedia); media.addEventListener('ended', stopMedia); rwd.addEventListener('click', mediaBackward); fwd.addEventListener('click', mediaForward); media.addEventListener('timeupdate', setTime); play. function playPauseMedia() { rwd.classList.remove('active'); fwd.classList.remove('active'); clearInterval(intervalRwd); clearInterval(intervalFwd); if(media.paused) { play.setAttribute('data-icon','u'); media.play(); } else { play.setAttribute('data-icon','P'); media.pause(); } } function stopMedia() { media.pause(); media.currentTime = 0; rwd.classList.remove('active'); fwd.classList.remove('active'); clearInterval(intervalRwd); clearInterval(intervalFwd); play.setAttribute('data-icon','P'); } let intervalFwd; let intervalRwd; function mediaBackward() { clearInterval(intervalFwd); fwd.classList.remove('active'); if(rwd.classList.contains('active')) { rwd.classList.remove('active'); clearInterval(intervalRwd); media.play(); } else { rwd.classList.add('active'); media.pause(); intervalRwd = setInterval(windBackward, 200); } } function mediaForward() { clearInterval(intervalRwd); rwd.classList.remove('active'); if(fwd.classList.contains('active')) { fwd.classList.remove('active'); clearInterval(intervalFwd); media.play(); } else { fwd.classList.add('active'); media.pause(); intervalFwd = setInterval(windForward, 200); } } function windBackward() { if(media.currentTime <= 3) { stopMedia(); } else { media.currentTime -= 3; } } function windForward() { if(media.currentTime >= media.duration - 3) { stopMedia(); } else { media.currentTime += 3; } } function setTime() { const minutes = Math.floor(media.currentTime / 60); const seconds = Math.floor(media.currentTime - minutes * 60); const minuteValue = minutes.toString().padStart(2, '0'); const secondValue = seconds.toString().padStart(2, '0'); const mediaTime = `${minuteValue}:${secondValue}`; timer.textContent = mediaTime; const barLength = timerWrapper.clientWidth * (media.currentTime/media.duration); timerBar.style.width = `${barLength}px`; } });