apache / apache/cordova-plugin-media

Not able to record audio in Android 10

Open
#322 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
391
Forks
762
PR merge metrics
No merged PRs in 30d

Description

The following code works in Android 8:
```
var onSuccess = function (e) {
console.log('onSuccess', e);
};
var onError = function (e) {
console.log('onError', e);
};
my_media = new Media(cordova.file.externalDataDirectory + 'audio.mp3', onSuccess, onError);
my_media.startRecord();
```

However startRecord gives an error {code: 1} in Android 10.

What have I tried with same result:

```
my_media = new Media(cordova.file.cacheDirectory + 'audio.mp3', onSuccess, onError);
my_media.startRecord();

my_media = new Media(cordova.file.applicationStorageDirectory + 'audio.mp3', onSuccess, onError);
my_media.startRecord();

my_media = new Media(cordova.file.dataDirectory + 'audio.mp3', onSuccess, onError);
my_media.startRecord();
```

I also tried to create file before recording:
```
resolveLocalFileSystemURL(cordova.file.externalDataDirectory , function (entry) {
entry.getFile('audio.mp3', {
create: true,
exclusive: false
}, function (fileEntry) {
console.log('getFile', fileEntry);
my_media = new Media(cordova.file.externalDataDirectory + 'audio.mp3', onSuccess, onError);
my_media.startRecord();
}, function (err) {
console.log(err);
});
}, function (err) {
console.log(err);
});
```

The file is created but recording does not start.
Please tell if I am doing something wrong or if this plugin is not working with Android 10+ so I will not waste my days trying to make it work.

P.S. similar issues suggests requestLegacyExternalStorage flag but it is not solving problem anymore because Play Market now requires apps to use API level 30.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported Media.startRecord() failure on Android 10/API 30 using the sample code and each listed Cordova file location. Use the onError callback's code 1 as the failing signal; done means recording starts successfully on Android 10+ without relying on requestLegacyExternalStorage.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, javascript
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.