Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "cordova-plugin-media-capture in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'cordova-plugin-media-capture' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

}, function (/* err */) {
        errorCB(new CaptureError(CaptureError.CAPTURE_INTERNAL_ERR));
    });
};
this.container.onclick = function () {
        // Cancel capture here
        errorCB(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
    };
captureAudio: function (successCallback, errorCallback, args) {
        var options = args[0];

        var audioOptions = new CaptureAudioOptions();
        if (typeof (options.duration) === 'undefined') {
            audioOptions.duration = 3600; // Arbitrary amount, need to change later
        } else if (options.duration > 0) {
            audioOptions.duration = options.duration;
        } else {
            errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
            return;
        }

        // Some shortcuts for long namespaces
        var CaptureNS = Windows.Media.Capture;
        var MediaPropsNS = Windows.Media.MediaProperties;
        var localAppData = Windows.Storage.ApplicationData.current.localFolder;
        var generateUniqueName = Windows.Storage.NameCollisionOption.generateUniqueName;

        var mediaCapture = new CaptureNS.MediaCapture();
        var mediaCaptureSettings = new CaptureNS.MediaCaptureInitializationSettings();
        var mp3EncodingProfile = new MediaPropsNS.MediaEncodingProfile.createMp3(MediaPropsNS.AudioEncodingQuality.auto); // eslint-disable-line new-cap
        var m4aEncodingProfile = new MediaPropsNS.MediaEncodingProfile.createM4a(MediaPropsNS.AudioEncodingQuality.auto); // eslint-disable-line new-cap

        mediaCaptureSettings.streamingCaptureMode = CaptureNS.StreamingCaptureMode.audio;
}, function () {
                                // if we here, we're totally failed to record either mp3 or m4a
                                errorCallback(new CaptureError(CaptureError.CAPTURE_INTERNAL_ERR));

                            });
                        });
if (err.number === -1072868846) {
                        // first we clear existing timeout to prevent success callback to be called with invalid arguments
                        // second we start same actions to try to record m4a audio
                        clearTimeout(stopRecordTimeout);
                        localAppData.createFileAsync('captureAudio.m4a', generateUniqueName).then(function (storageFile) {
                            capturedFile = storageFile;
                            mediaCapture.startRecordToStorageFileAsync(m4aEncodingProfile, capturedFile).then(function () {
                                stopRecordTimeout = setTimeout(stopRecord, audioOptions.duration * 1000);
                            }, function () {
                                // if we here, we're totally failed to record either mp3 or m4a
                                errorCallback(new CaptureError(CaptureError.CAPTURE_INTERNAL_ERR));

                            });
                        });
                    } else {
                        errorCallback(new CaptureError(CaptureError.CAPTURE_INTERNAL_ERR));

                    }
                });
            }, function () { errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES)); });
captureImage: function (successCallback, errorCallback, args) {

        var fail = function (code) {
            if (errorCallback) {
                errorCallback(new CaptureError(code || CaptureError.CAPTURE_INTERNAL_ERR));
            }
        };

        var options = args[0];

        var limit = options.limit || 1;
        if (typeof limit !== 'number' || limit < 1) {
            fail(CaptureError.CAPTURE_INVALID_ARGUMENT);
            return;
        }

        // Counter for already taken images
        var imagesTaken = 0;

        navigator.getUserMedia = navigator.getUserMedia ||
                         navigator.webkitGetUserMedia ||
                         navigator.mozGetUserMedia ||
                         navigator.msGetUserMedia;

        if (!navigator.getUserMedia) {
            fail(CaptureError.CAPTURE_NOT_SUPPORTED);
            return;
        }
var limit = options.limit || 1;
        if (typeof limit !== 'number' || limit < 1) {
            fail(CaptureError.CAPTURE_INVALID_ARGUMENT);
            return;
        }

        // Counter for already taken images
        var imagesTaken = 0;

        navigator.getUserMedia = navigator.getUserMedia ||
                         navigator.webkitGetUserMedia ||
                         navigator.mozGetUserMedia ||
                         navigator.msGetUserMedia;

        if (!navigator.getUserMedia) {
            fail(CaptureError.CAPTURE_NOT_SUPPORTED);
            return;
        }

        var ui = new CameraUI();
        ui.startPreview(limit, function (data) {
            // Check if we're done with capture. If so, then destroy UI
            if (++imagesTaken >= limit) {
                ui.destroyPreview();
            }

            // Array of resultant MediaFiles
            var mediaFiles = [];

            // save data to file here
            window.requestFileSystem(window.TEMPORARY, data.length * limit, function (fileSystem) {
                // If we need to capture multiple files, then append counter to filename
file.getMetadata(function (meta) {
                                mediaFiles.push(new MediaFile(file.name, file.toURL(), 'image/jpeg', meta.modificationTime, meta.size));
                                // Check if we're done with capture. If so, then call a successCallback
                                if (imagesTaken >= limit) {
                                    successCallback(mediaFiles);
                                }
                            }, fail);
                        };
captureAudio: function (successCallback, errorCallback, args) {
        var options = args[0];

        var audioOptions = new CaptureAudioOptions();
        if (typeof (options.duration) === 'undefined') {
            audioOptions.duration = 3600; // Arbitrary amount, need to change later
        } else if (options.duration > 0) {
            audioOptions.duration = options.duration;
        } else {
            errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
            return;
        }

        // Some shortcuts for long namespaces
        var CaptureNS = Windows.Media.Capture;
        var MediaPropsNS = Windows.Media.MediaProperties;
        var localAppData = Windows.Storage.ApplicationData.current.localFolder;
        var generateUniqueName = Windows.Storage.NameCollisionOption.generateUniqueName;

        var mediaCapture = new CaptureNS.MediaCapture();
var fail = function (code) {
            if (errorCallback) {
                errorCallback(new CaptureError(code || CaptureError.CAPTURE_INTERNAL_ERR));
            }
        };

Is your System Free of Underlying Vulnerabilities?
Find Out Now