Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhoneGap/Cordova iOS: capture video with a duration limit (ie. 30 seconds)

I would like to limit video capturing to 30 seconds. As of now the PhoneGap documentation says the following of iOS implementation:

"The duration parameter is not supported. Recording lengths cannot be limited programmatically."

I did find this post which seems to give the solution for a purely objective C implementation:

iPhone: 5 seconds video capture

The question is: Is this something that could "easily" be made into a phonegap plugin or is there some other reason phonegap hasn't been able to implement this? If you think it can be done - any information pointing me in the right direction is much appreciated! Thanks :)

like image 939
PotatoFro Avatar asked Apr 18 '12 15:04

PotatoFro


1 Answers

I'm trying to solve the same problem and may have a solution:

The capture.captureVideo() function returns an array of MediaFile objects. Those objects have a MediaFile.getFormatData() method that tells you what the duration of the file is and therefore you could reject the file if its too long...

Here's my solution:

 navigator.device.capture.captureVideo(function(mediaFiles) {

                mediaFiles[0].getFormatData(function(data) {

                    if(data.duration > 30) {
                        /* Tell the user the video is too long */
                    } else {
                        /* Video is less than the max duration...all good */
                    }
                });

        }, function(error) { /* An error occured */ },
null);
like image 120
SomethingOn Avatar answered Nov 15 '22 03:11

SomethingOn