cordova-plugin-media
cordova-plugin-media copied to clipboard
Not able to record audio in Android 10
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.
android:requestLegacyExternalStorage="true"
@yuganghe please read the last line of my question
Hey, it looks like it's fixed by #317. Personally, I've installed cordova-plugin-media
directly from GitHub by doing this: npm i --save apache/cordova-plugin-media#4093f7e
(4093f7e is the latest commit so far on master branch)
Hey, it looks like it's fixed by #317. Personally, I've installed
cordova-plugin-media
directly from GitHub by doing this:npm i --save apache/cordova-plugin-media#4093f7e
(4093f7e is the latest commit so far on master branch)
it work for me by apply the commit changes into cordova-plugin-media
@erisu i have tried below github as well but not working. i have tested in android 10. please give some information.
https://github.com/erisu/cordova-plugin-media
the solution that worked for me: since API 30 Android has restrictions on access to external storage.
install file plugin : cordova plugin add cordova-plugin-file
var onSuccess = function (e) { console.log('onSuccess', e); }; var onError = function (e) { console.log('onError', e); };
window.resolveLocalFileSystemURL(cordova.file.dataDirectory,function (directory) { var my_media = new Media(directory+'recording.mp3', onSuccess, onError ) }, err =>{ console.log('resolveLocalFileSystemURL ', JSON.stringify(err)); } );
and it works for me !!!!!
@kenfouo This did not fix the issue for me.
After a number of hours debugging this I finally got it working (my project is two years old):
What worked for me: In package.json -> devDependencies explicitly set versions to: "cordova-plugin-file": "^7.0.0", "cordova-plugin-media": "^6.1.0",
Then (without doing number 2 and 3 below I could not get it to work):
- Remove android platform
- delete node_modules folder
- delete plugins folder
- add android platform
- run android