cordova-plugin-media icon indicating copy to clipboard operation
cordova-plugin-media copied to clipboard

Recorded file neither saving nor playing

Open mayankkataria opened this issue 3 years ago • 13 comments

I'm using this plugin with ionic capacitor instead of cordova with command ionic cap sync. My code:

audioFile: MediaObject;
constructor(private media: Media, private plt: Platform, private file: File) {}
ionViewDidEnter() {
    this.plt.ready()
    .then(() => {
      setTimeout(() => {
        this.audioFile = this.media.create(this.file.externalRootDirectory + 'audiofile.mp3');
        this.audioFile.onStatusUpdate.subscribe(status => console.log('status: ', status));
        this.audioFile.onSuccess.subscribe(() => console.log('Action is successful'));
        this.audioFile.onError.subscribe(error => console.log('Error: ', error));
      }, 1000);
    })
    .catch(err => console.log('ready error: ', err));
}

record() {
    // When record button clicked
    this.audioFile.startRecord();
}

stop() {
    // When stop button clicked
    this.audioFile.stopRecord();
    this.audioFile.play();
}

When I clicked record, output was: Error: 1 and when I stopped recording than the output was status: 4 and Action is successful I expected to either play the recording or get audiofile.mp3 in file manager of my android device but I didn't got any of it.

mayankkataria avatar Jan 25 '21 11:01 mayankkataria

Facing same issue for android 10+ SDK 30. As per doc error:1 refers to MediaError.MEDIA_ERR_ABORTED = 1

zubinraja avatar Feb 13 '21 17:02 zubinraja

Same on iOS 14 with Ionic Capacitor:

Log just says: Media create INVALID Media startRecordingAudio INVALID Media stopRecordingAudio INVALID

Couldn't catch any other log from exceptions nor catching error promises, so I don't know how to proceed.

jahertor avatar Mar 01 '21 11:03 jahertor

Hi guys not sure if this might help the android guys but worked for me

Go into the android project AndroidManifest.xml file. Place the following tag: android:requestLegacyExternalStorage="true"

Like so inside the application tag:

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:usesCleartextTraffic="true"
        android:requestLegacyExternalStorage="true">

BLTowsen avatar Mar 25 '21 12:03 BLTowsen

Same situation here. Can't find any more information.

quauhtlimtz avatar Mar 30 '21 18:03 quauhtlimtz

same..

Kerulener avatar Apr 15 '21 11:04 Kerulener

This solution with the "requestLegacyExternalStorage" is soon going to be an issue.

https://developer.android.com/about/versions/11/privacy/storage

If I understand correctly, our apps won't be able to write to the external directory so easily anymore...

francoisduchemin avatar Apr 23 '21 12:04 francoisduchemin

Same issue here in Android API 30.

Any workaround to fix it?

android:requestLegacyExternalStorage="true" not work for me.

Thanks!

fgarcia5 avatar Jun 09 '21 22:06 fgarcia5

Same issue here in Android API 30.

Any workaround to fix it?

android:requestLegacyExternalStorage="true" not work for me.

Thanks!

Did you find any solution ??

21pg avatar Sep 28 '21 07:09 21pg

Same issue here in Android API 30. Any workaround to fix it? android:requestLegacyExternalStorage="true" not work for me. Thanks!

Did you find any solution ??

In my case my app required this feature, so I ended up developing my app with Flutter. You can make yourself an idea on how many time I spent trying to solve this particular problem.

jahertor avatar Sep 28 '21 07:09 jahertor

I also don't have any solution unfortunately... I cannot update my Android app right now.

francoisduchemin avatar Sep 28 '21 07:09 francoisduchemin

for android instead of this.file.externalRootDirectory try this.file.externalDataDirectory. it works for me. For android and iOS this directory works for me this.global.G_ExternalDirectory = this.platform.is('ios') ? this.file.dataDirectory : this.file.externalDataDirectory;

in addition to it, before audio recording I am checking audio and storage access permission explicitly.

this.diagnostic.requestMicrophoneAuthorization() and this.diagnostic.requestExternalStorageAuthorization()

see if that works for you too.

zubinraja avatar Sep 28 '21 08:09 zubinraja

In my case my app required this feature, so I ended up developing my app with Flutter. You can make yourself an idea on how many time I spent trying to solve this particular problem.

Nothing works for me.. I Have an app builder, In which 20K apps that depends on this plugin (required this feature)- I don't required to record and play. We use live stream e.g (-[(http://streams.radiobob.de/bob-chillout/aac-64/streams.radiobob.de/)]) and just want to play this audio stream on button click.. When I click play button, output is: Error: 1

https://github.com/apache/cordova-plugin-media/issues/315

21pg avatar Sep 29 '21 10:09 21pg

@zubinraja Thanks for you solution but not working for me. Still figure out . @21pg agreed.

bhandaribhumin avatar Oct 04 '21 12:10 bhandaribhumin