我需要知道在上传到服务器之前通过PhoneGap捕获的视频的持续时间。 MediaFile.getFormatData的文档有点模糊,似乎没有用。
我已经能够成功捕获并上传视频,因此所有这些都有效,只是持续时间部分没有。
我做错了什么?
在带有iOS 5.1.1的iPhone 4上运行
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);
答案 0 :(得分:2)
您正尝试以同步方式调用异步代码。请尝试这样:
mediaFiles[0].getFormatData(function(data) {
if(data.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.")
}
});
答案 1 :(得分:1)
试试这个:
navigator.device.capture.captureVideo(function(mediaFiles) {
mediaFiles[0].getFormatData(function(data) {
if(data.duration > 30) {
alert('Your video is longer than the allowed 30 seconds.');
}
});
}, function(error) { alert('An error occured'); }, null);