Use microphone in webrtc & media recorder simultaneously in Android? - 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

Related

Android Visualizer won't pick up audio from Spotify streaming music

I'm making an Android audio visualizer app for streaming Spotify music. I'm using Spotify's android-streaming-sdk which creates a local service (no need to have the Spotify app installed) and it plays music from within the app. I'm having a difficult time getting Androids Visualizer library to pick up any audio from Spotify (it works fine if I use a local .mp3 file).
//Start playing spotify track
player.playUri(MainActivity.operationCallback,
VisualizerModel.getInstance().getTrackURI(), 0, 0);
.... other code ....
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
int audioSessionId = mediaPlayer.getAudioSessionId();
visualizer = new Visualizer(audioSessionId);
visualizer.setCaptureSize(audioSampleSize);
visualizer.setDataCaptureListener(this, Visualizer.getMaxCaptureRate(), true, true);
visualizer.setEnabled(true);
If I run this, everything compiles and runs okay, but the visualizer does not pick up any audio. This makes me thing that the audio sessionId is not the same one as Spotify is playing on. However, if I switch the audioSessionId to 0 (which should listen to all the audio sessions mixed from what I understand) it crashes with this error:
E/AudioEffect: set(): AudioFlinger could not create effect, status: -1
E/visualizers-JNI: Visualizer initCheck failed -3
E/Visualizer-JAVA: Error code -3 when initializing Visualizer.
According to their documentation that error means: Operation failed due to bad object initialization.
I'm targetting API 24 (Android 7.0).
Please let me know if you have suggestions or an alternative to using Android's Visualizer library. I feel like my main problem is that I'm not sure how to find the audioSessionId that Spotify is playing on, and because Spotify's android-streaming-sdk is in beta (and not mentioned on their website) there is virtually no documentation on it from what I can see on Github.
Thank you for taking the time to read my issue!
I was facing the same error. Adding "android.permission.RECORD_AUDIO" to manifest and requesting for runtime permissions fixed the issue.
to protect privacy of certain audio data (e.g voice mail) the use of the visualizer requires the permission android.permission.RECORD_AUDIO
Also
Creating a Visualizer on the output mix (audio session 0) requires permission Manifest.permission.MODIFY_AUDIO_SETTINGS
Android docs for Visualizer class

MediaPlayer not working on some android devices

I am trying to play the mp3 file from web using media player class , on some devices it is working fine but for few devices it is giving following error .
QCMediaPlayer mediaplayer NOT present
Unable to create media player
error (-38, 0)
Attempt to call getDuration without a valid mediaplayer
any help on this will be of great help.
In general error -38 means you are trying to call a function in wrong state for the player.
In your case as error says, you call getDuration() when player is not prepared or started. Set setOnPreparedListener() then start the player mp.start(), then you can call getDuration().
Check this Tutorial to stream audio from web

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.

Android videoview video not play after once play video in webview

In WebView when I play a YouTube video it plays the video successfully but it gives following error message :
OnBufferingUpdateListener is null. Failed to send MEDIA_BUFFERING_UPDATE message.
Even if I finish this activity the video stops but still the above error continuously occurs.
When I open another activity and tried to play video in videoview control then it gives error message
Can't play video. and following error code -
E/MediaPlayer(10207): Error (-38,0)
Is there any way to solve these problems?

android: media recorder : start failed: -38

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.

Categories

Resources