captureVideo: function()

in src/windows/CaptureProxy.js [479:565]


    captureVideo: function (successCallback, errorCallback, args) {
        const options = args[0];
        const CaptureNS = Windows.Media.Capture;

        function fail (code, data) {
            const err = new CaptureError(code);
            err.message = data;
            errorCallback(err);
        }

        // Check if necessary API available
        if (!CaptureNS.CameraCaptureUI) {
            // We are running on WP8.1 which lacks CameraCaptureUI class
            // so we need to use MediaCapture class instead and implement custom UI for camera

            const proxy = new MediaCaptureProxy();

            proxy.captureVideo(function (videoFile) {
                videoFile.getBasicPropertiesAsync().done(
                    function (basicProperties) {
                        const result = new MediaFile(
                            videoFile.name,
                            'ms-appdata:///local/' + videoFile.name,
                            videoFile.contentType,
                            basicProperties.dateModified,
                            basicProperties.size
                        );
                        result.fullPath = videoFile.path;
                        successCallback([result]);
                    },
                    function (err) {
                        fail(CaptureError.CAPTURE_INTERNAL_ERR, err);
                    }
                );
            }, fail);
        } else {
            const videoOptions = new CaptureVideoOptions();
            if (options.duration && options.duration > 0) {
                videoOptions.duration = options.duration;
            }
            if (options.limit > 1) {
                videoOptions.limit = options.limit;
            }
            const cameraCaptureUI = new Windows.Media.Capture.CameraCaptureUI();
            cameraCaptureUI.videoSettings.allowTrimming = true;
            cameraCaptureUI.videoSettings.format = Windows.Media.Capture.CameraCaptureUIVideoFormat.mp4;
            cameraCaptureUI.videoSettings.maxDurationInSeconds = videoOptions.duration;
            cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.video).then(
                function (file) {
                    if (file) {
                        file.moveAsync(
                            Windows.Storage.ApplicationData.current.localFolder,
                            'cameraCaptureVideo.mp4',
                            Windows.Storage.NameCollisionOption.generateUniqueName
                        ).then(
                            function () {
                                file.getBasicPropertiesAsync().then(
                                    function (basicProperties) {
                                        const result = new MediaFile(
                                            file.name,
                                            'ms-appdata:///local/' + file.name,
                                            file.contentType,
                                            basicProperties.dateModified,
                                            basicProperties.size
                                        );
                                        result.fullPath = file.path;
                                        successCallback([result]);
                                    },
                                    function () {
                                        errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
                                    }
                                );
                            },
                            function () {
                                errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
                            }
                        );
                    } else {
                        errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
                    }
                },
                function () {
                    errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
                }
            );
        }
    },