0

I am trying to get duration for the video file.
I have tried using video tag and get the duration for .Mp4 file but just want to get video file duration in c# just by using file URL.

For example
http://media.jilion.com/videos/demo/midnight_sun_sv1_1_450p.mp4
once if I loaded this url.

AlessioX
  • 3,167
  • 6
  • 24
  • 40
ebi
  • 1
  • 1

1 Answers1

1

If you have the choice, JS version is easier. Plus, I don't have all the details of what you are trying to do, but videos are loaded client side so I think downloading videos server side only to check the duration is not the best option.

var video = $("#myVideo")[0];
var duration;

// Use of interval to fix issue http://stackoverflow.com/questions/2221029/problem-retrieving-html5-video-duration
var interval = window.setInterval(function() {
  // Video not ready yet
  if (video.readyState <= 0)
    return;
 
  duration = video.duration;
  $("#myTitle").text('Duration : ' + duration.toFixed(2) + 's');
  clearInterval(interval);
}, 200);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<video id="myVideo" width="300" height="150" src="http://media.jilion.com/videos/demo/midnight_sun_sv1_1_450p.mp4"></video>
<h3 id="myTitle"></h3>
bviale
  • 5,245
  • 3
  • 28
  • 48