android: media recorder : start failed: -38 - android

Brief: How to check if voice recording is already running in background in some other app.
Detail: if voice recording is already running in background from native app: Voice recorder.
Now I have implemented voice recording as one of feature in my application.
Problem: when i try recording in my app at the same time, it gives error :
: E/MediaRecorder: start failed: -38
: E/MyApp: [1162][com.sec.MyApp.multimedia.RecordMyVoice]java.lang.IllegalStateException
: E/MyApp: at android.media.MediaRecorder.start(Native Method)
: E/MyApp: at com.sec.MyApp.multimedia.RecordMyVoice.doInBackground(RecordMyVoice.java:100)
Code at 100th line in RecordMyVoice.java:
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.prepare();
mRecorder.start(); //code at 100th line
But problem is because already voice recording is running in background.
Therefore is there any way to stop voice recording if its running in some other app.
Any input would be of great help.

i've had the same Error -38, i found out that there is Another background service that uses the mic via (AudioRecord), when disabling the background service , it worked.

Check your file path, the directory must be existed.

Related

Use microphone in webrtc & media recorder simultaneously in Android?

I am using webrtc for video calling in android. I am simultaneously screen recording after call is connected in sender end. I am getting this error log in sender end. Receiver end voice is not hearing when screen recording is started using MediaRecorder. I think webrtc is not streaming audio to receiver end when media recorder is started using microphone.
Error
AudioRecord: start() status -38
2020-06-25 13:37:18.948 3276-5257/com.obs.booking E/WebRtcAudioRecord: WebRtcAudioRecord: Start recording error: AUDIO_RECORD_START_STATE_MISMATCH. AudioRecord.startRecording failed - incorrect state :1
2020-06-25 13:37:18.949 3276-5257/com.obs.booking E/AudioRecordJni: StartRecording failed!
2020-06-25 13:37:18.949 3276-5257/com.obs.booking E/libjingle: (voe_base_impl.cc:439): StartSend: Failed to start recording
2020-06-25 13:37:18.949 3276-5257/com.obs.booking E/libjingle: (voe_base_impl.cc:386): StartSend() failed to start recording
2020-06-25 13:37:18.949 3276-5257/com.obs.booking E/libjingle: (audio_send_stream.cc:245): AudioSendStream::Start failed with error: -1
Help me out to resolve this error.
The error message indicates that the audio recording is failed due to incorrect state.
This error "AUDIO_RECORD_START_STATE_MISMATCH" tells that when the start() methods is called the audio recording already is in progress.
It is possible there is a conflict between media-recording and WEBRTC audio recording.
To solve this there are several ways that I hope be useful:
1 - make sure the source of both are same.
2 - Try to stop webRTC before start the media-recorder

How to set MediaRecorder setOutputFile to null?

I am trying to create an audio recorder app that records audio and should save audio only when users click on the save button. But the problem I am facing is that as soon as recording stops it saves automatically. And if I try to set setOutputFile to null then the app crashes.
Code
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setOutputFile(AudioSavePathInDevice);
Does Anybody know how to save that audio recording manually?

VOIP Call Recording in Android

I am trying to record voip call of what's-app and some how able to trigger recording at the same time when an VOIP call is ongoing .
Trying the Below code to record the VOIP Call
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audiofile.getAbsolutePath());
try {
recorder.prepare();
} catch (IllegalStateException e)
{
e.printStackTrace();
}
recorder.start();
but for VOIP call whats app is also using AudioRecorder with the same Audio Source and whoever either my app Recording service or whatsapp able to get an instance of recorder will run perfectly and other app stucked due to Audio Resource Busy . Any suggestion how will i record the Voip Call

Call recording issue in Android

I want to implement call recording in my one app, So I have used below questions for reference:
Android Recording Incoming and Outgoing Calls
How To Record Incoming Call in android programmatically?
I am using below code to record a call
recorder.reset();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
But I have also try to use different audio source and output format but it's not recording properly
its recording one-sided call sometimes, and when changing to voice_call and voice_communication its not recording calls at all
In some thread, I found that in some devices it's not working properly but I found some apps in play store which works quite good
https://play.google.com/store/apps/details?id=com.appstar.callrecorder

Service to detect when MediaRecorder is called by any application

I have an AudioRecorder app that runs in a service smoothly, but when I try to use any Recorder app (Video/Voice Recorder), it gives the following error
Voice: Unable to start a new recording. Other applications are already recording
Video: Recording failed
a similar issue was raised here
I want to know if there is any possible way to set a service to listen to when a MediaRecorder.start() is being called by ANY app or even when the object is created.
Thanks.

Categories

Resources