Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to record audio in Android 10 #322

Open
julia-fix opened this issue Nov 11, 2021 · 7 comments
Open

Not able to record audio in Android 10 #322

julia-fix opened this issue Nov 11, 2021 · 7 comments

Comments

@julia-fix
Copy link

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.

@yuganghe
Copy link

android:requestLegacyExternalStorage="true"

@julia-fix
Copy link
Author

@yuganghe please read the last line of my question

@rozpuszczalny
Copy link

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)

@jpiero-exus
Copy link

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

@edvenkat
Copy link

@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

@kenfouo
Copy link

kenfouo commented Apr 27, 2022

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

@orhan-swe
Copy link

orhan-swe commented Sep 16, 2022

@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):

  1. Remove android platform
  2. delete node_modules folder
  3. delete plugins folder
  4. add android platform
  5. run android

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants