audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

How can I play audio in call mode like in whatsapp?

Open rafante opened this issue 4 years ago • 10 comments

Is it possible? I can't find a way to accomplish that with flutter. Could you help me?

rafante avatar Jan 16 '20 19:01 rafante

can you describe better what is call mode?

luanpotter avatar Jan 18 '20 15:01 luanpotter

can you describe better what is call mode?

Sure, it's like in WhatsApp. In WhatsApp if you play an audio file it will play it on speakers and if you are using earphones it will play on the earphones, but if you bring your cellphone close to your ears, the audio stop playing on the speakers and start playing like a phone call just into the ear

rafante avatar Jan 18 '20 19:01 rafante

I see. I think we must provide ways (if not already present) to play sound in all of those modes (speaker, headphone, etc), but maybe detecting whether the user has their phone up their ears or not could be done by another plugin? I assume you can use camera luminosity, accelerometer, mic sounds, or maybe even a combination of several sensors to guess that, and it seems to be a complex task that could be handled by an interesting plugin (not sure if the solution already exists in android/ios as well)

luanpotter avatar Jan 18 '20 23:01 luanpotter

I see. I think we must provide ways (if not already present) to play sound in all of those modes (speaker, headphone, etc), but maybe detecting whether the user has their phone up their ears or not could be done by another plugin? I assume you can use camera luminosity, accelerometer, mic sounds, or maybe even a combination of several sensors to guess that, and it seems to be a complex task that could be handled by an interesting plugin (not sure if the solution already exists in android/ios as well)

I think I didn't get myself clear. I'm not worried about the sensors or those other functionalities because I understand they should be handled by other means, but this plugin works pretty fine by playing audio through speakers if no earphone is connected or through earphone if there's any present. The problem is just that there's no option to make the sound plays through the standard call source. I've made a research and it seems it could be accomplished in android this way:

private AudioManager audioManager;
audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL); //See this part? This is what I'm asking for the plugin audioManager.setSpeakerphoneOn(false);

Hope you can get it. If not, thank you anyway. I understand such so basic functionality such as audio handling should be provided by google by default and it was not supposed to be necessary a plugin for that. But thank you for your efforts anyway =)

rafante avatar Jan 19 '20 00:01 rafante

I think we can have a option to set

audioManager.setMode(AudioManager.MODE_IN_CALL);

on the audioplayer on android, and we would need to find the equivalent parameter on iOS. We can just add a boolean to the play method, as long as it doesn't conflict with anything else.

are you willing to help out with a PR to add that feature?

luanpotter avatar Jan 20 '20 13:01 luanpotter

For iOS we can use setCategory [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

gopalkrishan123 avatar Mar 11 '20 10:03 gopalkrishan123

Hi @gopalkrishan123! If I understood you correctly so this is the same feature-request

This feature already implemented in Android. So we just need help with iOS implementation

beerline avatar Apr 27 '20 19:04 beerline

@gopalkrishan123, to calculate distance between cellphone and the ear, you can use this plugin

beerline avatar Apr 27 '20 19:04 beerline

Have implemented this in #515 and awaiting review.

nmazidi avatar May 13 '20 16:05 nmazidi

Hello! Any updates about this?

GrupoDO avatar Nov 16 '21 11:11 GrupoDO

Seems to be implemented in #515. Feel free to open a new issue, if it's not the case.

Gustl22 avatar Apr 05 '23 13:04 Gustl22