Answer the question
In order to leave comments, you need to log in
How to get the dimensions of a video file in JavaSript?
Actually, if you use FileReader to read the selected file before uploading it to the site, then for example, finding out the width or height of the image will not help: var img = new Image(file);
To work with audio, it will help: var audio = new Audio(file);
What about the video? I want to check the width and height of the video before uploading to the site. What are the ways? Or not to use FileReader for this ?
<input id="file" type="file"/>
<script>
var file = document.getElementById('file').files[0];
document.getElementById('file').addEventListener('change', read_file(file));
function read_file(){
var fr = new FileReader();
fr.onloaded = function(e){
var src = e.target.result;
document.getElementByTagName('body').appendChild('<video src="'+ src +'"></video');
var video = document.getElementByTagName('video')[0];
console.log(video.videoHeight); // Возвращает '0', хотя видео присутствует
}
}
</script>
Answer the question
In order to leave comments, you need to log in
after - var video = document.getElementByTagName('video')[0];
here is the code to do:
var interval = setInterval(function () {
if ( video.videoHeight > 0 ) {
clearInterval(interval);
console.log(video.videoHeight);
}
}, 200);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question