apache / cordova-plugin-media

Apache Cordova Media Plugin
https://cordova.apache.org/
Apache License 2.0
387 stars 765 forks source link

Recorded file neither saving nor playing #301

Open mayankkataria opened 3 years ago

mayankkataria commented 3 years ago

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.

zubinraja commented 3 years ago

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

jahertor commented 3 years ago

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.

BLTowsen commented 3 years ago

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">
quauhtlimtz commented 3 years ago

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

Kerulener commented 3 years ago

same..

francoisduchemin commented 3 years ago

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...

fgarcia5 commented 3 years ago

Same issue here in Android API 30.

Any workaround to fix it?

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

Thanks!

21pg commented 3 years ago

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 ??

jahertor commented 3 years ago

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.

francoisduchemin commented 3 years ago

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

zubinraja commented 3 years ago

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.

21pg commented 3 years ago

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

bhandaribhumin commented 3 years ago

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