audioplayers
audioplayers copied to clipboard
[1.0.1] iOS volume very low (sound is coming from earpiece)
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.
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?
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。
Hi , here same bug. The sound play into Ear speaker and won’t play in Bluetooth airpods and sound very low.
same issue on iOS 15.4.1.
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 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.
@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.
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);
@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 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.
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);
}
this code worked for me 😊
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?
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).
Hi! I would be interested looking into fixing this issue :)
Hi @tozu, you're welcome. Just start a Merge Request, if you feeling ready :)
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);
final AudioContext audioContext = AudioContext(
iOS: AudioContextIOS(
defaultToSpeaker: true,
category: AVAudioSessionCategory.ambient,
options: [
AVAudioSessionOptions.defaultToSpeaker,
AVAudioSessionOptions.mixWithOthers,
],
),
android: AudioContextAndroid(
isSpeakerphoneOn: true,
stayAwake: true,
contentType: AndroidContentType.music, // i change this
usageType: AndroidUsageType.media, // i change this
audioFocus: AndroidAudioFocus.gain, // i change this
),
);
AudioPlayer.global.setGlobalAudioContext(audioContext);
i change some android config, and work
@agordeev thanks this save my day
Worked for me with this config only on iOS:
iOS: AudioContextIOS(
defaultToSpeaker: true,
category: AVAudioSessionCategory.playAndRecord,
options: [
AVAudioSessionOptions.defaultToSpeaker,
AVAudioSessionOptions.mixWithOthers,
],
)
android has same issue
android has same issue
As far as I know, Android does not have this issue, the sound is coming from the speaker and not from the earpiece by default on android.
Set the phone volume to 0, still can play out the sound; set the phone volume to the maximum, but the sound played out is still the original size。Unable to adjust the volume level of playback
Found this in the SwiftAudioplayersDarwinPlugin
class definition. Hope this resolves any mystery around "why setAudioContext
doesn't work but setGlobalAudioContext
does".
I think it will be useful to update the documentation accordingly. Or let the Flutter wrapper also mention this in logs.
Consequently, a fix (if someone would like to work on it; I would have loved to but time doesn't permit :( ) for iOS could be to roll-over regular AudioContext to GlobalAudioContext, since it has been established that iOS does not allow player-specific audio contexts.
Good catch @utkarsh1097!
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);
That works for me!
The only change for iOS is 'category: AVAudioSessionCategory.playAndRecord' instead of 'category: AVAudioSessionCategory.ambient'
sorry, thank you for the answer, but I want to know Why before worked without that setting , I mean before I don't needed set all that is it for iOS update?
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);
sorry, thank you for the answer, but I want to know Why before worked without that setting , I mean before I don't needed set all that is it for iOS update?
Previously you probably used an earlier version of AudioPlayers where this bug doesn't exist. It shouldn't be that hard to fix within AudioPlayers, and we are very open to PRs for it. It should be a pretty easy fix, but we don't have any iOS devices to test with.
Can you tell us what version was this bug introduced in, incase we want to revert back to a version where this didn't exist?
@sameergoyal I think it was introduced in v1.0.0
Sounds like this is a default configuration issue?