如何获取通过PhoneGap捕获的视频的持续时间? [英] How do you get the duration of a video captured via PhoneGap?

查看:103
本文介绍了如何获取通过PhoneGap捕获的视频的持续时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道在上传到服务器之前通过PhoneGap捕获的视频的持续时间。 MediaFile.getFormatData 的文档是

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.

我已经能够成功捕获和上传视频,所以所有这一切都是工作,只是持续时间部分isn

I have been able to successfully capture and upload a video, so all of that is working, just the duration part isn't.

我做错了什么?

在搭载iOS 5.1.1的iPhone 4上运行

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);


推荐答案

您尝试以同步方式调用异步代码, / p>

You are trying to call async code in an synchronous manner. Try it like this instead:

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.")
    }
});

这篇关于如何获取通过PhoneGap捕获的视频的持续时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆