Osm Dev
Osm Dev

Reputation: 97

cordova audio recording is not firing , saying navigator.device is undefined

I am creating an application using cordova to record the voice and save in phone and i followed the instruction in link
1)http://plugins.cordova.io/#/package/org.apache.cordova.media-capture 2)https://cordova.apache.org/docs/en/3.0.0/cordova_device_device.md.html
but it is saying that navigator.device is not defined
added the plugin regarding the device cordova plugin add org.apache.cordova.device, but it is still showing the same error.

and in Xml (in app/res/xml/config.xml)

<feature name="Device">
    <param name="android-package" value="org.apache.cordova.Device" />
</feature>
(in app/AndroidManifest.xml)
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

still it is showing navigator.device is undefined
and my code is

    function Fnrecord() {
        debugger;

        OpenModalDialog('Alert', 'Voice Recording' + navigator.device +, '80%', '20%');
        navigator.device.capture.captureAudio(captureSuccess, captureError, { limit: 2 });

        function captureSuccess(mediaFiles) {
            var i, len;
            for (i = 0, len = mediaFiles.length; i < len; i += 1) {
                uploadFile(mediaFiles[i]);
            }
        }
        // Called if something bad happens.
        //
        function captureError(error) {
            var msg = 'An error occurred during capture: ' + error.code;
            //  navigator.notification.alert(msg, null, 'Uh oh!');
            OpenModalDialog('Alert', msg, '80%', '20%');
        }

        // A button will call this function
        //
        function captureAudio() {
            debugger;
            var capture = navigator.device.capture;
            OpenModalDialog('Alert', 'Voice Recording' + capture, '80%', '20%');
            // Launch device audio recording application,
            // allowing user to capture up to 2 audio clips
            navigator.device.capture.captureAudio(captureSuccess, captureError, { limit: 2 });
        }

        // Upload files to server
        function uploadFile(mediaFile) {
            var ft = new FileTransfer(),
                path = mediaFile.fullPath,
                name = mediaFile.name;

            ft.upload(path,
                "http://my.domain.com/upload.php",
                function (result) {
                    console.log('Upload success: ' + result.responseCode);
                    console.log(result.bytesSent + ' bytes sent');
                },
                function (error) {
                    console.log('Error uploading file ' + path + ': ' + error.code);
                },
                { fileName: name });
        }

    }

Upvotes: 1

Views: 1453

Answers (1)

user2398029
user2398029

Reputation: 6937

For me, the issue was that the device plugin was not installed:

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git

Upvotes: 1

Related Questions