0

I need to find th duration of videos from the url which was provided from the api using Javascript

For example If the url is

https://static.redoc.com/testing/yp8m8564btm.mp4

I need to find the duration in JS and I just want to display the duration with the video title I dont want to create any element in html just want to retrieve the durations as soon as the url is stored in a variable from api

Akshay
  • 15
  • 2
  • 4

1 Answers1

1

You could load it in via html and hide it with styling:

<video style="display: none;" id="myvid">
  <source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>

And read the meta data in JS after it has loaded

var myvid= document.getElementById('myvid');
console.log(myvid.duration) 

Credit goes to Mikushi for that answer - https://stackoverflow.com/a/2602558/9318217

Jacob Riches
  • 177
  • 8