In my app, I only want to play a sound when the device ringer is on. Currently the code I have works, but there is a delay for retrieving the device's current ringer status. I am using the audioplayers and sound_mode packages to do this.
_playSound(String sound) async {
String ringerStatus = await SoundMode.ringerModeStatus;
if (ringerStatus.contains("Normal Mode")) {
return await player.play(sound);
}
}
Edit: The problem is that in iOS you have to read the ringer status twice per the sound_mode package documentation.