Recording is not working on cordova-plugin-media - Can't use audio file

Hey guys,

I have a problem with the cordova-plugin-media plugin.
Its similar like Media Plugin (cordova-plugin-media) not recording or Cordova-plugin-media but I think this title is much better and we can clarify it here much better. But you can combine this topics if you like @moderators.

voiceMessage: MediaObject;

recordVoiceMessage() {
  // tested direct file:// path, without folder and with documents://
  this.voiceMessage = this.media.create(
    'documents://test.m4a',
    () => { },
    () => {
      alert('SUCCESS');
    },
    (error: MediaError) => {
      alert(JSON.stringify(error));
    }
  );
  this.voiceMessage.startRecord();
}

stopRecordVoiceMessage() {
  this.voiceMessage.stopRecord();
  this.voiceMessage.release();

  let speechmemeUri = 'test.m4a';
  this.file.readAsText(this.file.tempDirectory, speechmemeUri).then(res => {
    alert('OK: ' + JSON.stringify(res));
  }, err => { alert('ERR: ' + JSON.stringify(err)); });
  this.file.readAsDataURL(this.file.dataDirectory, speechmemeUri).then(res => {
    alert('OK: ' + JSON.stringify(res));
  }, err => { alert(JSON.stringify(err)); });
  this.file.readAsDataURL(this.file.cacheDirectory, speechmemeUri).then(res => {
    alert('OK: ' + JSON.stringify(res));
  }, err => { alert(JSON.stringify(err)); });
  this.file.readAsDataURL(this.file.externalCacheDirectory, speechmemeUri).then(res => {
    alert('OK: ' + JSON.stringify(res));
  }, err => { alert(JSON.stringify(err)); });
  this.file.readAsDataURL(this.file.documentsDirectory, speechmemeUri).then(res => {
    alert('OK: ' + JSON.stringify(res));
  }, err => { alert(JSON.stringify(err)); });
}

This is the script.
If I want to record I get this messages.

  1. Cannot use audio file from resource ‘test.m4a’
  2. Could not record audio at ‘test.m4a’

And

  1. Cannot use audio file from resource ‘file:///private/var/mobile/Containers/Data/Application/7381F546-C6A9-444F-A49A-CCAFFAF5B7A0/tmp/test.m4a’
  2. Could not record audio at ‘file:///private/var/mobile/Containers/Data/Application/7381F546-C6A9-444F-A49A-CCAFFAF5B7A0/tmp/test.m4a’

And

  1. Cannot use audio file from resource ‘documents://test.m4a’
  2. Could not record audio at ‘documents://test.m4a’

The question is why?

Must I enable something special that cordova / ionic is able to write to the storage of the device?
Or whats wrong with this?

Thanks in Advance for ideas! :smile:

1 Like

Same here!
See: https://github.com/driftyco/ionic-native/issues/1452