How to check duration of video in Angular 4.3.1 using ng2-file-upload?

1.1k views Asked by At

I am using ng2-file-upload for uploading videos and maximum duration of uploading is 15 minutes. So how can I get it's duration just before uploading it to server? These extensions are allowed only :- -.MOV -.MPEG4 -.AVI -.FLV -.3FPP -.WebM and -.MPEGS. Please reply if anyone knew it.

1

There are 1 answers

1
Mick On

You can include vanilla Javascript in your Angular application to do this.

The following will give you a duration (test on mp4):

var inputBox = document.getElementById("videoInput")

inputBox.onchange = function(files)  {
  alert("starting")
  var video = document.createElement('video');
  alert("video created")
  video.preload = 'metadata';
  video.onloadedmetadata = function() {
    alert("metadata loaded")
    var duration = video.duration;
    alert("duration is " + duration)
  }
  var selectedVID = document.getElementById("videoInput").files[0];
  video.src = URL.createObjectURL(selectedVID);
}
<div id="input-upload-file">
  <p>
  Video Upload Duration test
  </p>
  <input id="videoInput" type="file" class="upload" name="fileUpload">
</div>