Christheoreo
Christheoreo

Reputation: 393

Cordova Media Capture.CaptureAudio - "Error code: undefined"

I am having an issue with using the cordova media-capture plugin. I am using cordova 8.0.0, android 7.0.0. I am using the cordova device, cordova media capture plugins. Here is the lines of code from my config.xml file.

<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<plugin name="cordova-plugin-media-capture" spec="^3.0.2" />
<plugin name="cordova-plugin-device" spec="^2.0.2" />
<engine name="android" spec="^7.0.0" />
<engine name="browser" spec="^5.0.4" />

I have a button in my html which I use to trigger the event. I know that the event listener works as I have put an alert in the event handler. Here is the JS code I am using.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
  console.log(navigator.device.capture);
  document.getElementById('button-record').addEventListener("click", captureTheAudio);
}

function captureTheAudio(){
  alert("button click"); // gets here

  var captureSuccess = function(mediaFiles) {
    var i, path, len;
    for (i = 0, len = mediaFiles.length; i < len; i += 1) {
      path = mediaFiles[i].fullPath;
      // do something interesting with the file
      alert("worked"); //does not get here
    }
  };

  // capture error callback
  var captureError = function(error) {
    //navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
    alert('Error code: ' + error.code, null, 'Capture Error'); //Error code: undefined.
  };

  // start audio capture
  navigator.device.capture.captureAudio(captureSuccess, captureError);
}

The capture error handler is called but the error code is undefined. Could anyone provide a way to fix this issue?

Upvotes: 0

Views: 863

Answers (2)

Christheoreo
Christheoreo

Reputation: 393

Turns out - there is a current build error with the media-capture plugin. I used the media plugin instead and it records as intended, however the audio quality is poor.

Upvotes: 0

Stefan
Stefan

Reputation: 1253

For checking the errors you can use LogCat for Android on the emulatur or device for the respective application. The logcat output is best viewed via Android Studio. Additionally, you could use chrome remote debugging for getting access to the WebView console. The console sometimes offers you a good hint so you don't require LogCat...

The cordova media plugin uses an external application to record the audio, the application is opened via an Intent (https://github.com/apache/cordova-plugin-media-capture/blob/master/src/android/Capture.java#L232). However, also external storage is required to store the recorded audio, which requires a runtime permission.

Upvotes: 1

Related Questions