hiennguyen92 / flutter_callkit_incoming

Flutter Callkit Incoming
https://pub.dev/packages/flutter_callkit_incoming
MIT License
182 stars 313 forks source link

Speaker not working on android and have some issue on iOS #502

Open hankwu0315 opened 8 months ago

hankwu0315 commented 8 months ago

I use flutter_webrtc to implement video calls When flutter_callkit_incoming is not used, the speaker works fine, I use the following method to switch headphones or speakers: Helper.setSpeakerphoneOn(true);

If I use flutter_callkit_incoming, I cannot use setSpeakerphoneOn to switch the audio output on android sometimes audio output is speaker, sometimes is earpiece on iOS

Flutter version 3.16.3 vs Dart version 3.2.3 flutter_callkit_incoming: ^2.0.3 flutter_webrtc: ^0.9.22

mjjoshi commented 7 months ago

if you found any solution then let me know

DanielDiaz18 commented 4 months ago

any updates of this?

EDIT: update the package to 2.0.4+1 fixes this issue for me

hankwu0315 commented 4 months ago

any updates of this?

EDIT: update the package to 2.0.4+1 fixes this issue for me

That's good news! I'll try it

hankwu0315 commented 4 months ago

any updates of this?

EDIT: update the package to 2.0.4+1 fixes this issue for me

Unfortunately, still not working

waleedf112 commented 3 weeks ago

I have found a solution to this, the problem is this package (or maybe the OS) is defaulting to the earpiece instead of the speakers (make sense), and using Helper.setSpeakerphoneOn(true); or Helper.setSpeakerphoneOnButPreferBluetooth(); IS doing what it's supposed to, it's just that the OS and flutter_webrtc are racing each other.

you'll have to either:

1- set a delay after starting a call to toggle the speakers.

await FlutterCallkitIncoming.startCall(_).then((_) async {
  await Future<void>.delayed(const Duration(seconds: 3));
  // I noticed that a 3-second delay works consistently, experiment with it.
  await Helper.setSpeakerphoneOnButPreferBluetooth();
});

2- or, find a point where you're sure the OS has finished the process of starting the call, in my case using flutter_webrtc with BigBlueButton backend, I can wait for a message that notifies me of my state during the call (ex: IN_ECHO_TEST or IN_CONFERENCE) and toggling the speakers afterwards.

TLDR: toggle the speakers a few moments after starting the call, 2 - 3 seconds should work.