0

DEMO - https://codepen.io/syedazam/pen/vYEvEze?editors=0111

I am developing a component in which while the video is playing status bar has to be filled up, for single video it is working fine, as there will be multiple video for example : 1. if the videos are 3 - then 3 progress bar will be displayed

const video = document.querySelector('.video__player');
let t;
const togglePlay = function() { if (this.paused) { this.play();} else {this.pause();}}

const updateTime = function() {
  let time = document.querySelector('.video__time');
  console.log('time',time);
  let s = parseInt(this.currentTime % 60).toString().padStart(2, '0');
  console.log('time s',s);
  let m = parseInt((this.currentTime / 60) % 60);
  console.log('time m',m);
  let sep = ':';
  time.innerHTML = `${m}${sep}${s}`;
}

const updateProgress = function(videoEl = this) {
  let progress = document.querySelector('.video__progress');
  progress.setAttribute('aria-valuenow', getVideoProgress(videoEl));
  progress.style.setProperty('--width', getVideoProgressNormal(videoEl));
}

function startProgressUpdate() {
  updateProgress(video);
  t = window.requestAnimationFrame(startProgressUpdate);
}

function stopProgressUpdate() {
  if (t) {
    window.cancelAnimationFrame(t);
  }
}

const videoLoadedMeta = function() {
  let progress = document.querySelector('.video__progress');
  progress.setAttribute('aria-valuemax', this.duration);
}

/**
* getVideoProgressNormal
* Returns the current video progression as a normal of 1 (ex: 50% finished is 0.5)
* decimals = 4 // Minimum 4 decimals is recommended for a smooth 60fps update
*/
const getVideoProgressNormal = (videoEl = this, decimals = 4) => {
  return (videoEl.currentTime / videoEl.duration).toFixed(decimals);
}

const getVideoProgress = (videoEl = this, decimals = 4) => {
  return (videoEl.currentTime).toFixed(decimals);
}

video.addEventListener('click', togglePlay);
video.addEventListener('timeupdate', updateTime);
video.addEventListener('playing', startProgressUpdate);
video.addEventListener('ended', stopProgressUpdate);
video.addEventListener('pause', stopProgressUpdate);
video.addEventListener('loadedmetadata', videoLoadedMeta);

enter image description here Request you to shed some light !

Thanks!

enter image description here

Developer
  • 1,409
  • 2
  • 23
  • 46
  • check this if this helps you, though its in jquery https://stackoverflow.com/questions/8007511/playing-two-videos-in-sequence-in-chrome-by-using-the-video-tag also this https://www.codeproject.com/Questions/853157/How-to-play-array-of-Videos-in-HTML hope it helps you – Karan Tewari Jan 22 '20 at 13:12
  • Might be better to show a picture (or video clip) of your expected result. Not everyone who could solve your problem uses WhatsApp so might skip this. – VC.One Jan 22 '20 at 22:11
  • @VC.One : Tnx.. sure will add one... – Developer Jan 23 '20 at 05:22

0 Answers0