I want to limit the user to upload only videos with duration up to 30 sec.Is there any Way?
To display the duration in a pretty fashion, you'll need to use parseInt and modulus ( % ): // Assume "video" is the video node var i = setInterval(function() { if(video. readyState > 0) { var minutes = parseInt(video. duration / 60, 10); var seconds = video.
The Video duration function returns “NaN” if no video is set whereas if the video is streamed and has no predefined length, it returns “Inf” (Infinity).
$video_file = $getID3->analyze('path-to-your-video'); // Get the duration in string, e.g.: 4:37 (minutes:seconds) $duration_string = $video_file['playtime_string']; // Get the duration in seconds, e.g.: 277 (seconds) $duration_seconds = $video_file['playtime_seconds'];
Try this
<form action="#" method="post" enctype="multipart/form-data">
File: <input type="file" name="fup" id="fup" /><br>
Duration: <input type="text" name="f_du" id="f_du" size="5" /> seconds<br>
<input type="submit" value="Upload" />
</form>
<audio id="audio"></audio>
<script>
// Code to get duration of audio /video file before upload - from: http://coursesweb.net/
//register canplaythrough event to #audio element to can get duration
var f_duration =0; //store duration
document.getElementById('audio').addEventListener('canplaythrough', function(e){
//add duration in the input field #f_du
f_duration = Math.round(e.currentTarget.duration);
document.getElementById('f_du').value = f_duration;
URL.revokeObjectURL(obUrl);
});
//when select a file, create an ObjectURL with the file and add it in the #audio element
var obUrl;
document.getElementById('fup').addEventListener('change', function(e){
var file = e.currentTarget.files[0];
//check file extension for audio/video type
if(file.name.match(/\.(avi|mp3|mp4|mpeg|ogg)$/i)){
obUrl = URL.createObjectURL(file);
document.getElementById('audio').setAttribute('src', obUrl);
}
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With