Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS volume very low (sound is coming from earpiece) #1194

Closed
lijinshanmx opened this issue Jun 25, 2022 · 84 comments · Fixed by #1374 or #1408
Closed

iOS volume very low (sound is coming from earpiece) #1194

lijinshanmx opened this issue Jun 25, 2022 · 84 comments · Fixed by #1374 or #1408
Labels
bug help wanted platform-ios Affects the ios platform

Comments

@lijinshanmx
Copy link

Android device is ok, but volume is very low on ios (xsmax os version: 15.5). I see some same issue, but close with 1.0.0-rc4 fix. now i am use 1.0.1.

@AldanisVigo
Copy link

It's not the volume. I figured out that it's not playing out of the speaker properly like it's supposed to. Instead it's playing out of the earpiece. I tried setting the audio context like this

AudioContextAndroid androidContext = AudioContextAndroid( isSpeakerphoneOn: true, stayAwake: true, contentType: AndroidContentType.music, usageType: AndroidUsageType.media, audioFocus: AndroidAudioFocus.gain);
AudioContextIOS iosContext = AudioContextIOS( category: AVAudioSessionCategory.ambient, defaultToSpeaker: true, options: [ AVAudioSessionOptions.defaultToSpeaker, AVAudioSessionOptions.allowBluetooth, AVAudioSessionOptions.allowBluetoothA2DP ] );
player.play(UrlSource(_currentSong!.downloadUrl),volume: 1.0,ctx: AudioContext(android: androidContext, iOS: iosContext),mode: PlayerMode.lowLatency);

But it did not work on iOS. Still playing out of the earpiece. Be careful bringing up the volume too much to compensate out of the earpiece and get a "speakerphone" effect as you may be overdriving the earpiece speaker. Any ideers?

@lijinshanmx
Copy link
Author

Yes, you're right,it's really not playing out of the speaker。I turned the volume all the way up and the sound is still very low on ios。

@poupouneroot
Copy link

Hi , here same bug. The sound play into Ear speaker and won’t play in Bluetooth airpods and sound very low.

@sakatech-jp
Copy link

same issue on iOS 15.4.1.

@DSoe
Copy link

DSoe commented Jun 27, 2022

I ran into the same issue. This is what I did to solve. I created AudioContext for iOS with defaultToSpeaker: false and set it in AudioPlayer.global.setGlobalAudioContext(_getAudioContext()). That solved my audio super quiet issue on my iPhone Xs Max.

@AldanisVigo
Copy link

I ran into the same issue. This is what I did to solve. I created AudioContext for iOS with defaultToSpeaker: false and set it in AudioPlayer.global.setGlobalAudioContext(_getAudioContext()). That solved my audio super quiet issue on my iPhone Xs Max.

I switched to just_audio already but this looks like the correct solution here.

@agordeev
Copy link

agordeev commented Jul 1, 2022

@DSoe it's unclear how defaultToSpeaker: false could help. Can you please add a code of _getAudioContext()?

@AldanisVigo can you please paste the working example of using just_audio? I found it even less friendly, and it plays from earpiece too.

@agordeev
Copy link

agordeev commented Jul 1, 2022

Ok, so this code worked for me:

      final AudioContext audioContext = AudioContext(
        iOS: AudioContextIOS(
          defaultToSpeaker: true,
          category: AVAudioSessionCategory.ambient,
          options: [
            AVAudioSessionOptions.defaultToSpeaker,
            AVAudioSessionOptions.mixWithOthers,
          ],
        ),
        android: AudioContextAndroid(
          isSpeakerphoneOn: true,
          stayAwake: true,
          contentType: AndroidContentType.sonification,
          usageType: AndroidUsageType.assistanceSonification,
          audioFocus: AndroidAudioFocus.none,
        ),
      );
      AudioPlayer.global.setGlobalAudioContext(audioContext);

@AldanisVigo
Copy link

@DSoe it's unclear how defaultToSpeaker: false could help. Can you please add a code of _getAudioContext()?

@AldanisVigo can you please paste the working example of using just_audio? I found it even less friendly, and it plays from earpiece too.

import 'package:just_audio/just_audio.dart' show AudioPlayer, AudioSource;

Everything else is pretty much the same except for there's no Completion listener, but there is still a duration and position listener so whenerver position == duration it's the same thing as the completion listener if you need it. Hope that helps.

@DSoe
Copy link

DSoe commented Jul 5, 2022

@DSoe it's unclear how defaultToSpeaker: false could help. Can you please add a code of _getAudioContext()?

@AldanisVigo can you please paste the working example of using just_audio? I found it even less friendly, and it plays from earpiece too.

This is what_getAudioContext() has.

AudioContext _getAudioContext() {
    return AudioContext(
        android: AudioContextAndroid(
          isSpeakerphoneOn: false,
          stayAwake: true,
          contentType: AndroidContentType.music,
          usageType: AndroidUsageType.media,
          audioFocus: AndroidAudioFocus.gain,
        ),
        iOS: AudioContextIOS(
          defaultToSpeaker: false,
          category: AVAudioSessionCategory.playback,
          options: [AVAudioSessionOptions.mixWithOthers]
              + [AVAudioSessionOptions.allowAirPlay]
          + [AVAudioSessionOptions.allowBluetooth]
          + [AVAudioSessionOptions.allowBluetoothA2DP]
        )
    );
  }

Since setting defaultToSpeaker: true works for you, I am thinking setting globalAudioContext somehow fixes the audio volume too low issue on iOS. I am not sure though.

@TSurridge
Copy link

TSurridge commented Jul 24, 2022

I just had the same issue in a Flame Game (using FlameAudio) where on my iPhone I couldn't hear anything but it was working fine on my iPad. I was going crazy trying to figure this out. Thought maybe something was wrong with my phone. Tried it on my wife's phone same issue. Ended up needed to add the same info above and now both iPhone and iPad have volume. I tried both AVAudioSessionCategory.ambient and AVAudioSessionCategory.playback and either worked. Pretty sure like others have said the key is AVAudioSessionOptions.defaultToSpeaker

    if (!kIsWeb) {
      final AudioContext audioContext = AudioContext(
        iOS: AudioContextIOS(
          defaultToSpeaker: true,
          category: AVAudioSessionCategory.ambient,
          options: [
            AVAudioSessionOptions.defaultToSpeaker,
            AVAudioSessionOptions.mixWithOthers,
          ],
        ),
        android: AudioContextAndroid(
          isSpeakerphoneOn: true,
          stayAwake: true,
          contentType: AndroidContentType.sonification,
          usageType: AndroidUsageType.assistanceSonification,
          audioFocus: AndroidAudioFocus.none,
        ),
      );
          // NEEDED THIS audioContext or iPhone volume didn't work only BGM I could hardly hear
      AudioPlayer.global.setGlobalAudioContext(audioContext);
    }

@hgjinfan
Copy link

this code worked for me
😊

@hatemragab
Copy link

I just had the same issue in a Flame Game (using FlameAudio) where on my iPhone I couldn't hear anything but it was working fine on my iPad. I was going crazy trying to figure this out. Thought maybe something was wrong with my phone. Tried it on my wife's phone same issue. Ended up needed to add the same info above and now both iPhone and iPad have volume. I tried both AVAudioSessionCategory.ambient and AVAudioSessionCategory.playback and either worked. Pretty sure like others have said the key is AVAudioSessionOptions.defaultToSpeaker

    if (!kIsWeb) {
      final AudioContext audioContext = AudioContext(
        iOS: AudioContextIOS(
          defaultToSpeaker: true,
          category: AVAudioSessionCategory.ambient,
          options: [
            AVAudioSessionOptions.defaultToSpeaker,
            AVAudioSessionOptions.mixWithOthers,
          ],
        ),
        android: AudioContextAndroid(
          isSpeakerphoneOn: true,
          stayAwake: true,
          contentType: AndroidContentType.sonification,
          usageType: AndroidUsageType.assistanceSonification,
          audioFocus: AndroidAudioFocus.none,
        ),
      );
          // NEEDED THIS audioContext or iPhone volume didn't work only BGM I could hardly hear
      AudioPlayer.global.setGlobalAudioContext(audioContext);
    }

Not working on all devices how to fix?

@Gustl22 Gustl22 added the platform-ios Affects the ios platform label Aug 31, 2022
@spydon spydon changed the title [1.0.1] iOS volume very low [1.0.1] iOS volume very low (because sound is coming from earpiece) Sep 2, 2022
@spydon spydon pinned this issue Sep 5, 2022
@spydon spydon changed the title [1.0.1] iOS volume very low (because sound is coming from earpiece) [1.0.1] iOS volume very low (sound is coming from earpiece) Sep 5, 2022
@spydon
Copy link
Member

spydon commented Sep 12, 2022

If anyone wants to put up a PR for this it would be greatly appreciated (I don't have any Apple devices to properly test this with).

@spydon spydon changed the title [1.0.1] iOS volume very low (sound is coming from earpiece) iOS volume very low (sound is coming from earpiece) Oct 3, 2022
@tozu
Copy link

tozu commented Oct 3, 2022

Hi!
I would be interested looking into fixing this issue :)

@Gustl22
Copy link
Collaborator

Gustl22 commented Oct 6, 2022

Hi @tozu, you're welcome. Just start a Merge Request, if you feeling ready :)

@darajava
Copy link

Ok, so this code worked for me:

      final AudioContext audioContext = AudioContext(
        iOS: AudioContextIOS(
          defaultToSpeaker: true,
          category: AVAudioSessionCategory.ambient,
          options: [
            AVAudioSessionOptions.defaultToSpeaker,
            AVAudioSessionOptions.mixWithOthers,
          ],
        ),
        android: AudioContextAndroid(
          isSpeakerphoneOn: true,
          stayAwake: true,
          contentType: AndroidContentType.sonification,
          usageType: AndroidUsageType.assistanceSonification,
          audioFocus: AndroidAudioFocus.none,
        ),
      );
      AudioPlayer.global.setGlobalAudioContext(audioContext);

This works, but AVAudioSessionCategory.ambient causes the audio not to be played on iOS when the Ring/Silence switch is activated. AVAudioSessionCategory.playback is what I wanted.

@chloelamplugh
Copy link

@imaNNeoFighT Thank you! According to this it should work with audioplayers: ^1.2.0. If not we have to rethink what could have gone wrong generally.

Now with audioplayers: ^2.0.0 this configuration should work theoretically, so that the sound is coming from loud speakers:

  AudioPlayer.global.setGlobalAudioContext(
    AudioContext(
      iOS: AudioContextIOS(
        category: AVAudioSessionCategory.playback,
        options: const [
          AVAudioSessionOptions.mixWithOthers,
          AVAudioSessionOptions.defaultToSpeaker,
        ],
      ),
    ),
  );

or using the default values should also lead to the same behavior:

  AudioPlayer.global.setGlobalAudioContext(AudioContext());

If not something must have gone during this PR #1374. But I honestly don't know what. You may can test the output in our example app to make sure nothing else is responsible for something going wrong.

For anyone who is confused about how to make this work, I added the "AudioPlayer.global.setGlobalAudioContext(AudioContext());" line in my 'init state'. See below:

` void initState() {
super.initState();
_audioPlayer = AudioPlayer();
AudioPlayer.global.setGlobalAudioContext(const AudioContext());
getURL();

//Listen to states: playing, paused, stopped
_audioPlayer.onPlayerStateChanged.listen((PlayerState state) {
  if (mounted) {
    // Check if the widget is still mounted
    setState(() {
      _playerState = state;
      _isPlaying = state == PlayerState.playing;
    });
  }
});

//Listen to audio duration
_audioPlayer.onDurationChanged.listen((newDuration) {
  if (mounted) {
    // Check if the widget is still mounted
    setState(() {
      duration = newDuration;
    });
  }
});

//Listen to audio position
_audioPlayer.onPositionChanged.listen((newPosition) {
  if (mounted) {
    // Check if the widget is still mounted
    setState(() {
      position = newPosition;
    });
  }
});

}`

@spydon
Copy link
Member

spydon commented Apr 11, 2023

Folks, can you try with the newly released AudioPlayers 4.0.0?
Hopefully this is solved now.

@skibos
Copy link

skibos commented Apr 27, 2023

Folks, can you try with the newly released AudioPlayers 4.0.0? Hopefully this is solved now.

I checked and after update to 4.0.1 it works perfect. Can be closed

@asmodeoux
Copy link

Hey guys, my issue is similar so I'll write my report/suggestion here. I use sound effects and a microphone at the same time in my app, and I noticed that if I set the category to playAndRecord the audio gets very quiet. It happens no matter what other options I choose, because basically the system wants to duck the audio to let the microphone record sound better.

The only way I found to fix it is to fork the lib and change the line which updates the category to:
try session.setCategory(category, mode: AVAudioSession.Mode.default, options: combinedOptions)

Once I use this mode parameter it gets fine. Is there any way the lib could support my case? Maybe there should be a Dart method to update iOS sound mode?

@spydon
Copy link
Member

spydon commented May 25, 2023

Hey @asmodeoux, this is not the same issue, please open a new one for your issue. :)

@Djihanegh
Copy link

Djihanegh commented Jun 23, 2023

still having the same issue :
using audioplayers: ^4.1.0
Flutter version : 3.10.2

final AudioContext audioContext = const AudioContext(
    iOS: AudioContextIOS(
      category: AVAudioSessionCategory.playAndRecord,
      options: [
        //  AVAudioSessionOptions.defaultToSpeaker,
        AVAudioSessionOptions.allowAirPlay,
        AVAudioSessionOptions.allowBluetooth,
        AVAudioSessionOptions.allowBluetoothA2DP,
        AVAudioSessionOptions.mixWithOthers,
      ],
    ),
    android: AudioContextAndroid(
      isSpeakerphoneOn: true,
      stayAwake: true,
      contentType: AndroidContentType.music,
      usageType: AndroidUsageType.media,
      audioFocus: AndroidAudioFocus.gain,
    ),
  );
@override
  void initState() {
    super.initState();
    audioPlayer.setAudioContext(audioContext);
  }

@spydon
Copy link
Member

spydon commented Jun 23, 2023

still having the same issue :
using audioplayers: ^4.1.0
Flutter version : 3.10.2

final AudioContext audioContext = const AudioContext(
    iOS: AudioContextIOS(
      category: AVAudioSessionCategory.playAndRecord,
      options: [
        //  AVAudioSessionOptions.defaultToSpeaker,
        AVAudioSessionOptions.allowAirPlay,
        AVAudioSessionOptions.allowBluetooth,
        AVAudioSessionOptions.allowBluetoothA2DP,
        AVAudioSessionOptions.mixWithOthers,
      ],
    ),
    android: AudioContextAndroid(
      isSpeakerphoneOn: true,
      stayAwake: true,
      contentType: AndroidContentType.music,
      usageType: AndroidUsageType.media,
      audioFocus: AndroidAudioFocus.gain,
    ),
  );
@override
  void initState() {
    super.initState();
    audioPlayer.setAudioContext(audioContext);
  }

If you don't change the AudioContext at all, do you still have the same problem?

@Djihanegh
Copy link

still having the same issue :
using audioplayers: ^4.1.0
Flutter version : 3.10.2

final AudioContext audioContext = const AudioContext(
    iOS: AudioContextIOS(
      category: AVAudioSessionCategory.playAndRecord,
      options: [
        //  AVAudioSessionOptions.defaultToSpeaker,
        AVAudioSessionOptions.allowAirPlay,
        AVAudioSessionOptions.allowBluetooth,
        AVAudioSessionOptions.allowBluetoothA2DP,
        AVAudioSessionOptions.mixWithOthers,
      ],
    ),
    android: AudioContextAndroid(
      isSpeakerphoneOn: true,
      stayAwake: true,
      contentType: AndroidContentType.music,
      usageType: AndroidUsageType.media,
      audioFocus: AndroidAudioFocus.gain,
    ),
  );
@override
  void initState() {
    super.initState();
    audioPlayer.setAudioContext(audioContext);
  }

If you don't change the AudioContext at all, do you still have the same problem?

In the beginning I wasn't changing the AudioContext, and yes it was working like that, then I checked GitHub answers here, I tried to change the AudioContext and its still the same.

@spydon
Copy link
Member

spydon commented Jun 25, 2023

@Djihanegh can you post the content of your pubspec.lock file?

Gustl22 added a commit that referenced this issue Jul 6, 2023
# Description

Supersedes #1501

* Introduce `AudioContextConfigRoute` to allow forcing audio to
`speaker` or `earpiece` (this can be extended to e.g. bluetooth devices)
for both iOS and Android
* ios: change default AVAudioSessionCategory from `.playAndRecord` to
`.playback` to not play from earpiece as in record mode (see #1194)
* ios: remove default `AVAudioSessionOptions.defaultToSpeaker` to allow
playing from system default device instead of speaker only (see #1486)
* android: change default AudioContextAndroid.isSpeakerphoneOn from
`true` to `false` to allow playing from system default device instead of
speaker only (see #1486)
* ios: remove default `AVAudioSessionOptions.mixWithOthers` to interrupt
audio of other apps, like in Android
* android: change default AudioContextAndroid.stayAwake from `true` to
`false` to not stay awake, like in iOS

## Breaking Change

### Migration instructions

|Before|After|
|---|---|
|`AudioContextAndroid()`|`AudioContextAndroid(isSpeakerphoneOn: true,
stayAwake: true)`|
|`AudioContextIOS()`|`AudioContextIOS(category:
AVAudioSessionCategory.playAndRecord, options:
[AVAudioSessionOptions.mixWithOthers,
AVAudioSessionOptions.defaultToSpeaker])`|
|`AudioContextConfig()`|`AudioContextConfig(route:
AudioContextConfigRoute.speaker, stayAwake: true})`|


## Related Issues

Closes #1491
Closes #1486
#1194
@MlecznyU
Copy link

Hi,

I have been following this thread for some time. As soon as I saw that a fix had been merged, I immediately upgraded audioplayers to version 5.0.0.

Unfortunately, in the logs, I keep getting the same error for iOS. Regardless of the configuration, it is practically the same every time. The only change is when the defaultToSpeaker option is removed.

My configuration

 const audioContext = AudioContext(
      android: AudioContextAndroid(
        isSpeakerphoneOn: true,
        stayAwake: true,
        contentType: AndroidContentType.music,
        usageType: AndroidUsageType.assistanceSonification,
        audioFocus: AndroidAudioFocus.gain,
      ),
      iOS: AudioContextIOS(
        category: AVAudioSessionCategory.ambient,
        options: [
          AVAudioSessionOptions.allowBluetooth,
          AVAudioSessionOptions.allowBluetoothA2DP,
          AVAudioSessionOptions.defaultToSpeaker,
        ]
      )
    );
    AudioPlayer.global.setAudioContext(audioContext);

Error:

[as_client]     AVAudioSession_iOS.mm:2191  Error: category option 'defaultToSpeaker' is only applicable with category 'playAndRecord'
[as_client]     AVAudioSession_iOS.mm:2367  Failed to set category, error: -50
flutter: ----------------FIREBASE CRASHLYTICS----------------
flutter: PlatformException(DarwinAudioError, Error configuring global audio session: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)", null, null)
flutter: 
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
<asynchronous suspension>

Without defaultToSpeaker option:

[as_client]     AVAudioSession_iOS.mm:2367  Failed to set category, error: -50
flutter: ----------------FIREBASE CRASHLYTICS----------------
flutter: PlatformException(DarwinAudioError, Error configuring global audio session: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)", null, null)
flutter: 
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
<asynchronous suspension>

And here is my pubspec.lock

  audioplayers:
    dependency: "direct main"
    description:
      name: audioplayers
      sha256: "2f4c0da9b483b45695d01dc738e1597d7137ae40fc2fa702f13ccc10efc706a2"
      url: "https://pub.dev"
    source: hosted
    version: "5.0.0"
  audioplayers_android:
    dependency: transitive
    description:
      name: audioplayers_android
      sha256: "7f18bb6c7de01684444e8cba577e3c3aee0ec379897f62ad4b8259d1e22f8c61"
      url: "https://pub.dev"
    source: hosted
    version: "4.0.0"
  audioplayers_darwin:
    dependency: transitive
    description:
      name: audioplayers_darwin
      sha256: "80e341e6b2b364420516f2707271ec47f63b9b22766aa7f7d484601190c316a7"
      url: "https://pub.dev"
    source: hosted
    version: "5.0.0"
  audioplayers_linux:
    dependency: transitive
    description:
      name: audioplayers_linux
      sha256: cca3f272c7186dd2e0025b8864e1413ac5e081d74b17e28b02ceb2df4c110235
      url: "https://pub.dev"
    source: hosted
    version: "3.0.0"
  audioplayers_platform_interface:
    dependency: transitive
    description:
      name: audioplayers_platform_interface
      sha256: "47eae55e99ced11589998cf27e4eaabf5b475a7bd8bea7516ee6c2536a2e1abf"
      url: "https://pub.dev"
    source: hosted
    version: "6.0.0"
  audioplayers_web:
    dependency: transitive
    description:
      name: audioplayers_web
      sha256: "9f155590c6ba9ba469df637f4729264e4234dc3941ece4690dad63ffac19b5af"
      url: "https://pub.dev"
    source: hosted
    version: "4.0.0"
  audioplayers_windows:
    dependency: transitive
    description:
      name: audioplayers_windows
      sha256: "8813b712ba919bb324bde5e3ba97edc81bface945953a54a3dea70b5608bcc70"
      url: "https://pub.dev"
    source: hosted
    version: "3.0.0"

@spydon
Copy link
Member

spydon commented Jul 27, 2023

@MlecznyU if you don't add any custom iOS context at all, do you still get the same problem?

@MlecznyU
Copy link

@MlecznyU if you don't add any custom iOS context at all, do you still get the same problem?

No, error only occurs when custom context is provided.

@spydon
Copy link
Member

spydon commented Jul 27, 2023

@MlecznyU if you don't add any custom iOS context at all, do you still get the same problem?

No, error only occurs when custom context is provided.

Can't you just change the category from ambient to playAndRecord like it says in the error message then? 🤔

@MlecznyU
Copy link

@MlecznyU if you don't add any custom iOS context at all, do you still get the same problem?

No, error only occurs when custom context is provided.

Can't you just change the category from ambient to playAndRecord like it says in the error message then? 🤔

I tested all AVAudioSessionCategory and each is giving me the same error

@spydon
Copy link
Member

spydon commented Jul 27, 2023

Alright, please open a new issue for this, since it is not the same issue as this one.

@anmollimje-mp
Copy link

final session = await AudioSession.instance;
await session.configure(const AudioSessionConfiguration.music());

You can use this to make audio comming from Speaker

@j-ixcayau
Copy link

Hi @MlecznyU, for me the solution for this error was to just change the category to playAndRecord:

Error:

[as_client]     AVAudioSession_iOS.mm:2191  Error: category option 'defaultToSpeaker' is only applicable with category 'playAndRecord'
[as_client]     AVAudioSession_iOS.mm:2367  Failed to set category, error: -50
flutter: ----------------FIREBASE CRASHLYTICS----------------
flutter: PlatformException(DarwinAudioError, Error configuring global audio session: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)", null, null)
flutter: 
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
<asynchronous suspension>

Without defaultToSpeaker option:

[as_client]     AVAudioSession_iOS.mm:2367  Failed to set category, error: -50
flutter: ----------------FIREBASE CRASHLYTICS----------------
flutter: PlatformException(DarwinAudioError, Error configuring global audio session: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)", null, null)
flutter: 
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
<asynchronous suspension>

Like This:

static AudioContext get getContext => const AudioContext(
      iOS: AudioContextIOS(
        category: AVAudioSessionCategory.playAndRecord,
        options: [
          AVAudioSessionOptions.mixWithOthers,
          AVAudioSessionOptions.defaultToSpeaker,
        ],
      ),
      android: AudioContextAndroid(
        isSpeakerphoneOn: true,
        stayAwake: true,
        contentType: AndroidContentType.speech,
        usageType: AndroidUsageType.assistanceSonification,
        audioFocus: AndroidAudioFocus.gain,
      ),
    );

@fullflash
Copy link

fullflash commented Nov 24, 2023

According to Apple docs.
defaultToSpeaker
You can set this option only when using the playAndRecord category.

https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions/1616462-defaulttospeaker

@asadbekdev
Copy link

final session = await AudioSession.instance; await session.configure(const AudioSessionConfiguration.music());

You can use this to make audio comming from Speaker

Thanks bro! You SAVED ME!

@MyisCARRY
Copy link

I still got the issue on 6.0.0. None of the above solutions work for me.

@Gustl22
Copy link
Collaborator

Gustl22 commented May 14, 2024

@MyisCARRY can you plz open a new issue, where you also share your code to reproduce? This issue has been tackled and probably the error is somewhere else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment