Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am integrating a functionality to record audio in service,it is working well and good in below android 10 devices and also in android 10 audio file is generated with that certain amount of time recorded but that file produces empty audio.I dont know where I have made the mistake.Suggest a solution to avoid this problem.

What I have tried:

Java
MediaRedorder recorder;

			recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
			recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
			recorder.setAudioEncoder(MediaRecorder.AudioEncoder.HE_AAC);
			recorder.setAudioSamplingRate(32);
			recorder.setAudioEncodingBitRate(160 * 1024);


This is the mediarecorder part to record audio and converting output as mp3.
Posted
Updated 23-Apr-20 6:23am
Comments
David Crow 21-Apr-20 10:43am    
"it is working well and good in below android 10 devices and also in android 10 audio file is generated with that certain amount of time recorded but that file produces empty audio."

So your code works on Android 9 devices and below, but on Android 10 devices (and above), no audio file is produced. Is my understanding correct?
karthi72 22-Apr-20 1:25am    
yes David
David Crow 22-Apr-20 8:29am    
Are any exceptions being thrown? What does your call to setOutputFile() look like?
karthi72 23-Apr-20 2:45am    
Yes failed to setup recorder and throws audio recording issue.
String rec="file_name.mp3";
File file=new File(rec);
recorder.setOutputFile(rec);
karthi72 23-Apr-20 6:13am    
Fixed the error and audio file is generated as well without the recording.

1 solution

Are you sure this is working in Android 9 (Pie)? From what I can see, Google were set to prevent background apps from using the camera or microphone back in 2018:
Android P won’t let apps secretly use your mic or camera in the background - The Verge[^]

I don't know whether there's an extra permission you can request to bypass this. It's certainly not something an app should be able to do without warning the user.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900