How to check microphone is already been use or not flutter? - android

I am building a chat application in which I am sending voice messages. Now when I am calling or any other mobile app is using a microphone then my chat app voice record does not work. How I can check the status of the microphone in a flutter whether it's already in use or not. Thanks

You can try to check flutter audio_session
interceptSession = await AudioSession.instance;
AudioSession.instance.then((audioSession) async {
await audioSession.configure(AudioSessionConfiguration(
avAudioSessionCategory: AVAudioSessionCategory.playAndRecord));
});
await interceptSession.interceptSession.setActive(true);

This plugin informs the operating system of the nature of your audio app (e.g. game, media player, assistant, etc.) and how your app will handle and initiate audio interruptions (e.g. phone call interruptions). It also provides access to all of the capabilities of AVAudioSession on iOS and AudioManager on Android, providing for discoverability and configuration of audio hardware.

Related

Is it possible to play sound effects with Android Auto using app types other than media-apps?

Is it possible to play sound effects with Android Auto using app types other than media-apps (Messaging apps, Navigation, parking & charging apps)?
When I try to play a sound effect using "SoundPool API", it is muted and there is no sound while Android Auto is running.
Is there any good way?
My Source code
https://github.com/LeoAndo/android-auto-automotive-training/blob/main/SoundPoolAutoApp/app/src/main/java/com/leoleo/helloautoapp/sound/MainSoundPlayer.kt
https://github.com/LeoAndo/android-auto-automotive-training/blob/main/SoundPoolAutoApp/app/src/main/java/com/leoleo/helloautoapp/auto/MainScreen.kt
There has been progress.
With the implementation of voice-guidance, it was successful to run the app on the DHU and output sound from the smartphone speaker.(app type: POI)
references:
https://developer.android.com/training/cars/apps/navigation#voice-guidance
https://developer.android.com/guide/topics/media-apps/audio-focus
Was self resolved. By installing the implementation of audio focus, we were able to make sound on the car side.(App Type: POI)
Reference

Android tv box (TX3 mini) run app without connecting display

I am trying to use my android tv box (TX3 mini) like a radio. The app I build using react native and expo work and the audio does play when the app is in the background. The audio is coming through AV port and not through HDMI. However when I unplug the HDMI after launching the app, the audio stop working. Is this setting i have to configure in the Android box to keep the audio and the app running when HDMI (display) is unplug or something i have set in my app when coding? I look for setting in the code, but could not find one.
I am using import { Audio } from 'expo-av' library.
Audio settings:
await Audio.setAudioModeAsync({
allowsRecordingIOS: false,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
playsInSilentModeIOS: true,
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
shouldDuckAndroid: true,
staysActiveInBackground: true,
playThroughEarpieceAndroid: true
});
Once the app is running i want to disconnect the display and keep the audio playing on the speaker.
Let me know if you need more details and thanks for any input.
Thanks,
A

How to detect if a headphones / a headset is connected to an Android device in React Native

I am making a calling app where users may or may not use headphones / a headset. On an incoming video call I am using react-native-incall-manager to turn the speaker on / allow speaker phone. The basic InCallManager.start({ media: 'video' }); method works and allows detection of a new audio device being plugged in such as headphones, and if this happens, the headphone and mic plugged in work as expected.
The problem comes in the case that headphones are already plugged in to the device before a call starts, because the InCallManager.setSpeakerphoneOn(true); method is called at that time. InCallManager.start({ media: 'video' }); doesn't account for devices already connected and the headphones do not work, the normal speaker does even though headphones are plugged in.
react-native-incall-manager recommends using DeviceEventEmitter from react-native to detect native events such as changes in connected audio devices, but this module is deprecated.
Here it is recommended to use NativeEventEmitter, but this seems very complex and seems to require the native Java (Android) modules to be written and used in conjunction with it.
How can I detect changes in connected audio devices in Android in React Native?
Here it is recommended to use NativeEventEmitter, but this seems very complex and seems to require the native Java (Android) modules to be written and used in conjunction with it.
You don't need to write a native Java module for this job since NativeEventEmitter can pick up events that were sent through RCTDeviceEventEmitter.
So example from react-native-incall-manager README
import { DeviceEventEmitter } from 'react-native';
DeviceEventEmitter.addListener('Proximity', function (data) {
// --- do something with events
});
can be easily rewritten to this
import { NativeEventEmitter, NativeModules } from 'react-native';
const eventEmitter = new NativeEventEmitter(NativeModules.InCallManager);
eventListener = eventEmitter.addListener('Proximity', event => {
// do something with events
});
Just don't forget to clean up once you no longer need event listeners
eventListener.remove();
If you want to detect changes in connected audio devices you can subscribe to onAudioDeviceChanged event from react-native-incall-manager.
It sends something like this whenever there is a change in connected audio devices or device that will output sound
{"availableAudioDeviceList": "[\"BLUETOOTH\",\"SPEAKER_PHONE\",\"EARPIECE\"]", "selectedAudioDevice": "EARPIECE"}

How to handle RTP session in Xamarin forms for Android and IOS?

I am trying make an application that will allow a registered client to make an audio call to another registered client using Wi-Fi(It doesn't require internet).
I was able to successfully register and make call using SIP.
After the call is picked up, I don't know how to handle the RTP stream and connect it with the microphone and speaker of the phone(Android and IOS) to perform normal calling functionality.
I am using Xamarin and SIP Sorcery library. I am new to Xamarin and mobile application development.
Below is a part of code to explain myself a little better:
async Task Call()
{
Console.WriteLine("Start of Calling section");
rtpSession = new RTPMediaSession((int)SDPMediaFormatsEnum.PCMU, AddressFamily.InterNetwork);
// May be somthing like this to connect audio devices to RTP session.
//get microphone
//get speaker
//ConnectAudioDevicesToRtp(rtpSession, microphone, speaker);
// Place the call and wait for the result.
bool callResult = await userAgent.Call(DESTINATION, ssid, userName, registerPassword, domainHost, rtpSession);
if (callResult)
{
Console.WriteLine("Call attempt successful. Start talking");
//I am reaching to this point and need help with how to move forward from here to support audio calling functionality for both Android and IOS
}
else
{
Console.WriteLine("Call attempt failed.");
}
}
Any help or direction would be appreciated. Thank you.
I looked at the documentation from SIP Sorcery, there I found only an example for windows (https://sipsorcery.github.io/sipsorcery/articles/sipuseragent.html), but not for ios or android.
Here is the description from SIP Sorcery for cross platform (https://sipsorcery.github.io/sipsorcery/). I think you need the SIPSorceryMedia.FFmpeg library

Recording voice calls in android

I want to make an app that records incoming and outgoing calls. I am using the media recorder to do so and also I am using service/broadcastreceiver to detect phone state change. I have set the audio source as Audiosource.VOICE_CALLS.I am able to record voices at my end but not from the other end. The same happens when the audio source is set as Audiosource.MIC.
Please suggest a solution.
You cannot access the incall audio stream in Android using the public SDK. Call audio is not exposed to apps, and you can only do this if you modify Android at a source level, and then build and install a new image from the customized source to your device.

Categories

Resources