I am using PhoneGap Build to build an iOS application and using weinre to debug. So far so good.

I am trying to use the media-capture and file APIs to capture a video and get its base64 representation. I can get the video recorder to open, take a video, and return. The problem is I can not get resolveLocalFileSystemURL to open the path. Every time it returns with an error code of 5 to which I can not seem to find a single answer as to what that means. This is running on a real device so it is not a problem with the emulator.

I have checked every post I could find via Google. Have been sratching my head for days on this one. Everyone who proposed an answer was either using Xcode-- as opposed to Build-- or the answer simply did not work for me.

Below is my code. Below that is the console output.

elements["media_video"].onclick = function(event) {
    navigator.device.capture.captureVideo(
        function(files) {
            for ( var i = 0 ; i < files.length ; ++i ) {
                var file = files[i];

                var name = file.name;
                var path = file.fullPath;
                var type = file.type;
                var lastModifiedDate = file.lastModifiedDate;
                var size = file.size;

                console.log(0, name, path, type, lastModifiedDate, size);

                var reader = new FileReader();
                reader.onloadend = function(event) {
                    console.log(3, event.target.result);
                };

                window.resolveLocalFileSystemURL(
                    path,
                    function(entry) {
                        console.log(1, entry.name);

                        reader.readAsDataURL(entry);
                        // send base64 data to server
                    },
                    function(error) {
                        console.log(2, error.code);
                    }
                );
            }
        },
        function(error) {},
        {
            limit:  1
        }
    );
};

0 "capturedvideo.MOV" "/private/var/mobile/Applications/[application uuid]/tmp/capture/capturedvideo.MOV" "video/quicktime" 1409866447000 205788
2 5

Figured it out.

For anyone looking resolveLocalFileSystemURL() expects a valid URL (file:// required). Also you must strip off /private for... some reason (ask Apple).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.