I need to know the duration of a video captured via PhoneGap before uploading to the server. The documentation for the MediaFile.getFormatData is a little vague and doesn’t seem to be working.
I have been able to successfully capture and upload a video, so all of that is working, just the duration part isn’t.
What am I doing wrong?
Running on an iPhone 4 with iOS 5.1.1
navigator.device.capture.captureVideo(function(mediaFile) {
if(mediaFiles.length == 1) {
$('#video_url').val(mediaFiles[0]);
var profileVideo = document.getElementById('profile-video');
profileVideo.src = mediaFiles[0].fullPath;
var formatData;
mediaFiles[0].getFormatData(function(data) {
formatData = data;
});
if(formatData.duration > 30) {
$('#infoMessage').html("Your video is longer than the allowed 30 seconds. Please record a new video. You can trim your video after it's been recorded.")
}
}
}, function(error) {
}, null);
You are trying to call async code in an synchronous manner. Try it like this instead: